/* Navigation JS - START */
$(function() {
//To display megamenu
const navLink = '.aig-header .cmp-navigation__group .cmp-navigation__item--level-0.cmp-navigation__item > a';
const mobileNav = '.button.mobile-icon';
$(navLink).each(function(){
if($(this).parent().find('.submenu-links').length === 0){
$(this).parent().addClass('no-submenulinks');
}
});
$(navLink).hover(function() {
displayMegaMenu(this);
if($(this).parent().find('.submenu-links').length == 0){
$('.overlay').removeClass('show');
}
});
$('.srOnlyNavBtn.primary').on('click', function () {
displayMegaMenu(this, true);
});
//to display sub-links
$('.srOnlyNavBtn.submenu').on('click',function() {
displaySubMenu(this);
});
//To close the Megamenu when out of Header navigation
$(navLink).closest('ul').mouseleave(closeMegamenu);
// To remove empty submenu '+' button
$('.srOnlyNavBtn.submenu').each(function(){
if(!$(this).next('.aig-submenu1').length){
$(this).remove();
}
});
//To reset tertiary level class names
$(navLink).mouseout(function() {
$('.submenu-links').removeClass('inactive-link');
$('.submenu-links .active-link').removeClass('active-link');
$('.aig-submenu1 .aig-submenu1').hide().attr('aria-expanded', 'false');
$(this).parent().find('.srOnlyNavBtn.primary').removeClass('active');
$(this).parent().find('.srOnlyNavBtn.primary').text('+');
$(this).parent().find('.srOnlyNavBtn.primary').attr('aria-expanded','false');
if($(this).parent().find(".cmp-navigation__item--level-3.cmp-navigation__item--active > a.activeLink").length>0){// to display selected submenu level 3 by default other than RiskSolutions
$(this).parent().find(".cmp-navigation__item--level-2.cmp-navigation__item--active > a.active").trigger('mouseenter');
}
if($(this).parent().find('.cmp-navigation__item--level-4.cmp-navigation__item--active > a.activeLink').length>0){
$(this).parent().find('.cmp-navigation__item--level-3.cmp-navigation__item--active > a.active').trigger('mouseenter');
}
if($(this).parent().find('.cmp-navigation__item--level-3 a.currentItemLink').length>0){// to display submenu by default for risk solution level 3
$(this).parent().find('.cmp-navigation__item--level-2 > a.currentItemLink').trigger('mouseenter');
}
});
//To close megamenu by clicking close button
$('.aig-submenu .closeBtn a').click(closeMegamenu);
//To close megamenu on press of enter or space key when the focus is in close button
$('.aig-submenu .closeBtn a').on('keydown', function (e) {
let keyCode = e.keyCode;
if(keyCode === 32 || keyCode === 27){
$(document).find('.hover > span button').focus();
closeMegamenu();
} else {
return false;
}
});
//to close megamenu when esc key is pressed start
$('.aig-submenu').on('keydown', function (e) {
let keyCode = e.keyCode;
if(keyCode === 27){
$(document).find('.hover > span button').focus();
closeMegamenu();
}
});
//to close megamenu when esc key is pressed end
$('.aig-submenu .closeBtn a ').on('keydown', function (e) {
let keyCode = e.keyCode;
if (keyCode === 13) {
$(document).find('.hover > span button').focus();
closeMegamenu();
}
});
//close menu + icon if esc key press
$('.aig-header .srOnlyNavBtn').on('keydown', function (e) {
let keyCode = e.keyCode;
if (keyCode === 27) {
$(document).find('.hover > span button').focus();
closeMegamenu();
}
});
//if condition to check submenu-intro and submenu-links
if ($('.aig-submenu .menu-container .submenu-intro').length > 0) {
//submenu intro to close btn
$('.aig-submenu .menu-container .submenu-intro h2 a').on('keydown', function (e) {
const keyCode = e.keyCode;
if (keyCode === 9 && e.shiftKey) {
e.preventDefault();
$(this).closest('.menu-container').find('.closeBtn a').focus();
}
});
//submenu-intro is detected transfer of focus from submenu-links to submenu intro last link
$('.aig-submenu .menu-container .submenu-links .cmp-navigation__item--level-1:first-child a').on('keydown', function (e) {
const keyCode = e.keyCode;
if (keyCode === 9 && e.shiftKey) {
e.preventDefault();
$(this).closest('.submenu-links').siblings('.submenu-intro').find('a:last-child').focus();
}
});
} else {
//if submenu-intro is not present
$('.aig-submenu .menu-container .submenu-links .cmp-navigation__item--level-1:first-child a').on('keydown', function (e) {
const keyCode = e.keyCode;
if (keyCode === 9 && e.shiftKey) {
e.preventDefault();
$(this).closest('.menu-container').find('.closeBtn a').focus();
}
});
}
//shift focus to previous element when shift+Tab is pressed from close button
$('.aig-submenu .closeBtn a').on('keydown', function (e) {
const keyCode = e.keyCode;
if(keyCode === 9){
if(e.shiftKey){
$(this).parent().siblings('.submenu-links').find('.cmp-navigation__item--level-1:last-child a').focus();
//if the last link have 2nd level submenu links , focus on + icon
if($(this).siblings('.aig-submenu1')){
$(this).parent().siblings('.submenu-links').find('.cmp-navigation__item--level-1:last-child button').focus();
} else {
$(this).parent().siblings('.submenu-links').find('.cmp-navigation__item--level-1:last-child a').focus();
}
} else{
//goto first link in megamenu if only tab key is pressed
$(this).closest('.menu-container').find('a:first').focus();
}
}
});
//Tab on close icon should focus on first link of submenu when there is no submenu intro
if ($('.aig-submenu .menu-container .submenu-intro').length === 0) {
$('.aig-submenu .closeBtn a').on('keydown', function (e) {
const keyCode = e.keyCode || e.which;
e.preventDefault();
if (keyCode === 9) {
$(this).closest('.menu-container').find('.cmp-navigation__item--level-1:nth-child(2) > a').focus();
}
if(keyCode === 9 && e.shiftKey){
$(this).parent().siblings('.submenu-links').find('.cmp-navigation__item--level-1:last-child a').focus();
//if the last link have 2nd level submenu links , focus on + icon
if($(this).siblings('.aig-submenu1')){
$(this).parent().siblings('.submenu-links').find('.cmp-navigation__item--level-1:last-child button').focus();
} else {
$(this).parent().siblings('.submenu-links').find('.cmp-navigation__item--level-1:last-child a').focus();
}
}
});
// Shift the focus to close icon when we shift+tab on first submenu link
$('.aig-submenu .menu-container .submenu-links .cmp-navigation__item--level-1:nth-child(2) > a').on('keydown', function (e) {
const keyCode = e.keyCode || e.which;
if (keyCode === 9 && e.shiftKey) {
e.preventDefault();
$(this).closest('.menu-container').find('.closeBtn > a').focus();
}
});
}
//To display tertiary level links in megamenu
$('.aig-submenu .cmp-navigation__item.cmp-navigation__item--level-2 > a').mouseover(function() {
$('.aig-submenu1 .aig-submenu1').hide();
$('.aig-submenu1 .aig-submenu1').attr('aria-expanded', 'false');
$(this).parents('ul').find('a').removeClass('active-link');
const subIntroStatus = $(this).closest('.aig-submenu').find('.submenu-intro').length === 0 ;
const submenuHeight = $('.submenu-links').innerHeight();
//change tertiary links styling on open/close
if($(this).parent().find('.aig-submenu1').length) {
$('.submenu-links').addClass('inactive-link');
$(this).parent().children('.aig-submenu1').show().attr('aria-expanded', 'true');
$(this).addClass('active-link');
$('.cmp-navigation__item--level-3 > a').removeClass('submenu-active submenu-inactive');
/* Set the min height for the sub menu */
const ulHeight = $(this).parent().find("ul").innerHeight() + 50;
if(submenuHeight < ulHeight && subIntroStatus){
$(this).closest('.submenu-links').css("min-height",ulHeight);
}
} else {
//To reset tertiary link styles
$('.submenu-links').removeClass('inactive-link');
}
});
//To display second level links in megamenu
$('.aig-submenu').each(function(){
const $subMenu = $(this);
const subIntroStatus = $subMenu.find('.submenu-intro').length === 0 ;
$subMenu.css({visibility: 'hidden', display: 'block'});
$subMenu.find('.cmp-navigation__item.cmp-navigation__item--level-1 > a').each(function() {
//change tertiary links styling on open/close
if ($(this).parent().find('.aig-submenu1').length) {
const ulLevel1 = $(this).closest('.cmp-navigation__item--level-1').parent();
$(this).parent().children('.aig-submenu1').show();
// To check offset position
const uiLevel1Height = ulLevel1.height() + ulLevel1.offset().top + 50;
const uiLeve21Height = $(this).siblings('.aig-submenu1').find('ul').height() + $(this).offset().top;
const uiLevel3Diff = ulLevel1.offset().top + $(this).siblings('.aig-submenu1').find('ul').height();
// Comparing both Level 1 & 2 height
if(uiLevel1Height < uiLeve21Height){
if(subIntroStatus){
$(this).closest('.submenu-links').css("min-height",uiLeve21Height);
}
if(uiLevel3Diff > $(this).offset().top){
// add class if submenu height and ul height are equal
if($(this).closest('.cmp-navigation__group').height() === $(this).closest('.submenu-links').height()) {
$(this).parent('.cmp-navigation__item--level-1').addClass('menu-align-top');
}
}else{
$(this).parent('.cmp-navigation__item--level-1').addClass('menu-align-bottom');
}
}else{
if(subIntroStatus){
$(this).closest('.submenu-links').css("min-height",uiLevel1Height);
}
}
$(this).parent().children('.aig-submenu1').hide();
}
if(subIntroStatus){
$(this).closest('.submenu-links').css({'margin-left':'unset'});
}
});
$subMenu.removeAttr('style');
});
$('.aig-submenu .cmp-navigation__item.cmp-navigation__item--level-1 > a').mouseover(function() {
//change tertiary links styling on open/close
const submenuHeight = $('.submenu-links').innerHeight();
if ($(this).parent().find('.aig-submenu1').length) {
$(this).parent().children('.aig-submenu1').show().attr('aria-expanded', 'true');
}
});
//To display 4th level links in megamenu
$('.aig-submenu1 .aig-submenu1').removeAttr('style');
$('.aig-submenu .cmp-navigation__item.cmp-navigation__item--level-3 > a').mouseover(function() {
$('.aig-submenu1 .aig-submenu1 .aig-submenu1').hide();
$('.aig-submenu1 .aig-submenu1 .aig-submenu1').attr('aria-expanded', 'false');
$(this).parents('.cmp-navigation__item--level-3').parent().find('a').removeClass('submenu-active');
const submenuHeight = $('.submenu-links').innerHeight();
//change 4th level links styling on open/close
if ($(this).parent().find('.aig-submenu1').length) {
$('.submenu-links').addClass('inactive-link');
$(this).parent().children('.aig-submenu1').show().attr('aria-expanded', 'true');
$(this).addClass('active-link');
$(this).parents('.cmp-navigation__item--level-3').parent().find('a').addClass('submenu-inactive');
$(this).addClass('submenu-active');
} else {
//To reset 4th level link styles
$(this).parents('.cmp-navigation__item--level-3').parent().find('a').removeClass('submenu-active submenu-inactive');
}
});
//To toggle search bar display on clicking search button
$('.search-button .cmp-button').click(function(e) {
if ($(mobileNav).css('display') === 'none') {
e.preventDefault();
$('#headerSearch, .header-search').toggle();
$('.search-button').toggleClass('close');
$("button").attr("aria-label","close button");
if($('.search-button.close').length){
$('.aig-header .header-search form .cmp-form-text input').focus();
}
//if search input field is expanded, collapse it
if($(this).attr('aria-expanded') == 'true'){
$(this).attr('aria-expanded', 'false');
$("button").attr("aria-label","search button");
}
//if search input field is not expanded, open it and have close button
if($(this).attr('aria-expanded') == 'false' && $('.search-button.close').length){
$(this).attr('aria-expanded', 'true');
}
}
if ($(window).width() < 961 ){
let mobileRedirect = $('[name="mobile-search-redirect"]').val();
window.location.href = window.location.origin + mobileRedirect;
}
});
//To append aria attribute for tracker input (for accessibility compliance)
$('.header-search form .aig-form-tracker input').attr('aria-label', 'Aig tracker');
//To append aria attribute for Utility navigation links
$('.right-nav-container > .cmp-container .image:nth-child(1)').attr('role', 'navigation').attr('aria-label', 'Global link');
$('.right-nav-container > .cmp-container .image:nth-child(2)').attr('role', 'navigation').attr('aria-label', 'Search link');
//To append aria attribute for hamburger menu
$(mobileNav).find('button').attr('aria-label', 'Mobile hamburger button');
if($(mobileNav).length > 0) {
$('.right-nav-container, .headernavigation').addClass('hidden');
}
// mobile menu scroll bar top align when we open
$('.aig-login-button, .back-to-nav-btn').click(function() {
let isScrollTOp = false;
if(!isScrollTOp){
$(".aig-submenu").scrollTop($(this).offset().top-100);
isScrollTOp = true;
}});
// To toggle mobile menu on clicking hamburger menu
$('.button.mobile-icon button').click(function() {
// mobile menu scroll bar top align when we open
let isScrollTOp = false;
if(!isScrollTOp){
$(".aig-submenu").scrollTop($(this).offset().top-100);
isScrollTOp = true;
}
if($('body').hasClass("hide-nav-level-one")===false){
$(window).scrollTop(0);
}
$('.right-nav-container, .headernavigation').toggleClass('show');
$('.overlay').toggleClass('sm-show');
$(mobileNav).toggleClass('close');
$('.header-search').hide();
$('.search-button').removeClass('close');
$('.aig-submenu').hide();
$('.aig-submenu1').hide();
$('a.cmp-navigation__item-link').removeClass('hover');
$('.aig-login-mobile').hide();
//To append aria attribute for search box
if ($(this).attr('aria-expanded') === 'true') {
$(this).attr('aria-expanded', 'false');
} else {
$(this).attr('aria-expanded', 'true');
}
// To close Login section
$('.aig-login-mobile .cmp-container .text:first .cmp-text').trigger('click');
$('body').removeClass("hide-nav-level-one");
});
$('.button.mobile-icon button').attr('aria-expanded', 'true');
// To insert navigation button in mobile view
$(navLink).each(function() {
if(this.innerHTML.indexOf('custom-icons')>0 || $(this).parent().find(".aig-submenu li").length<1){
$(this).css({'display':'block'});
} else{
$(''+this.innerHTML+' ').insertAfter(this);
}
});
// To display navigation dropdown in mobile view
$('body').on('click', '.mobile-nav-button', function() {
$(window).scrollTop(0);
$(this).parent().find('.aig-submenu').toggle();
// Toggel the first level submenu1 for authored links
$(this).parent().find('a.cmp-navigation__item-link').toggleClass('hover');
//To append aria attribute for mobile navigation
if ($(this).attr('aria-expanded') === 'true') {
$(this).attr('aria-expanded', 'false');
} else {
$(this).attr('aria-expanded', 'true');
}
$('body').addClass("hide-nav-level-one");
let currMenuTitle = $(this).prev().html();
$('.nav-title-mobile').html(currMenuTitle);
});
$('body').on('click', '.back-to-nav-btn', function() {
$('body').removeClass("hide-nav-level-one");
closeMegamenu();
});
//To format nested sub menu lists
$('.submenu-links').each(function() {
if (!$(this).find('ul ul').length) {
$(this).addClass('first-level-links').attr('aria-label', 'Single level links');
}
});
//To format tertiary sub menu links
$('.aig-submenu1 a').each(function() {
if ($(this).parent().find('.aig-submenu1').length) {
$(this).addClass('active');
}
});
//To add tertiary level navigation link in mobile
$('.cmp-navigation__item--level-2 .active').each(function() {
$('Tertiary Link ').insertAfter(this);
});
//To display tertiary level navigation in mobile
$('.cmp-navigation__item--level-2 .active+button').click(function() {
$(this).parent().children('.aig-submenu1').toggle();
});
//aria-attributes
$('.closeBtn').removeAttr('role aria-label').find('a').attr({
'role': 'button',
'aria-label': 'Close menu'
});
//To create overlay for menu component
$('
').prependTo('body');
$('.overlay').mouseover(function() {
$('.aig-submenu .closeBtn a').trigger('click');
});
//To remove linking for ghost node
$('.submenu-links a[data-ghost-node="true"]').each(function() {
$(this).removeAttr('href');
});
$('.submenu-links a[data-ghost-node="true"]').click(function(e) {
e.preventDefault();
});
// To display the submenu in level1 for not authored links
//$('.aig-submenu .submenu-links:not(.authored-links) ul li.cmp-navigation__item--level-1 > a').mouseover(function() {
$('.aig-submenu .submenu-links ul li.cmp-navigation__item--level-1 > a').mouseover(function() {
const aigSubmenu1 = $('.submenu-links .aig-submenu1');
aigSubmenu1.hide();
aigSubmenu1.attr('aria-expanded', 'false');
aigSubmenu1.removeClass('inactive-submenu');
if ($(this).parent().find('.aig-submenu1').length) {
$(this).parent().children('.aig-submenu1').show().attr('aria-expanded', 'true');
$('.submenu-links').addClass('inactive-link');
$(this).addClass('active-link');
}else{
$('.submenu-links').removeClass('inactive-link');
}
});
// on mouse leave remove the active and incative class //
$('.aig-submenu .submenu-links ul li.cmp-navigation__item--level-1 > a').mouseleave(function() {
$(this).removeClass('active-link');
$(this).parent().closest('.submenu-links').removeClass('inactive-link');
});
// on mouse over of level2 links for not authored links
$('.aig-submenu .submenu-links .cmp-navigation__item.cmp-navigation__item--level-2 > a').mouseover(function() {
$('.submenu-links').addClass('inactive-link');
$(this).parents('.cmp-navigation__item--level-1').children('a').addClass('active-link');
$(this).parent().closest('.aig-submenu1').removeClass('inactive-submenu');
//change tertiary links styling on open/close
if ($(this).parent().find('.aig-submenu1').length) {
$(this).parent().closest('.aig-submenu1').addClass('inactive-submenu');
}
});
// To check level-1 has sumenu for not authored links//
$('.submenu-links .cmp-navigation__item--level-1').each(function(){
if($(this).find('.aig-submenu1').length){
$(this).children('a').addClass('active');
}
});
//To add arrow to navigation link in mobile
$('.aig-submenu .submenu-links ul li .active').each(function() {
$('Arrow Link ').insertAfter(this);
});
//To display submenu on button arrow click in mobile
$('.aig-submenu .submenu-links ul li .active+button').click(function() {
$(this).parent().children('.aig-submenu1').toggle();
});
//To display megamenu in tablet devices over 1024px resolution
const navLink1 = '.aig-header .headernavigation ul li .submenu-links ul li.cmp-navigation__item--level-1 > a.active';
const navLink2 = '.aig-header .headernavigation ul li .submenu-links ul li.cmp-navigation__item--level-2 > a.active';
$(navLink).add(navLink1).add(navLink2).on('click', function(e) {
if (/Android|webOS|iPhone|iPad|iPod/i.test(navigator.userAgent) && window.screen.width > 960) {
if (!$(this).hasClass('tab-hover')) {
$(this).parents('.cmp-navigation__group').find('.tab-hover').removeClass('tab-hover');
e.preventDefault();
}
//Add class for tablet devices only
$(this).addClass('tab-hover');
} else{
$('.button.mobile-icon button').trigger('click');
}
});
/* adjust the submenu position */
$('.aig-submenu').each(function(){
const $subMenu = $(this);
const subIntroStatus = $subMenu.find('.submenu-intro').length !== 0 ;
$subMenu.css({visibility: 'hidden', display: 'block'});
let aigSubmenuHeight = $subMenu.outerHeight();
let aigSubmenuOffsetTop = $subMenu.offset().top;
/* adjust for level 1 submenus*/
$subMenu.find('.cmp-navigation__item.cmp-navigation__item--level-1 > a').each(function() {
//alignSubmenu(this,aigSubmenuHeight,aigSubmenuOffsetTop,subIntroStatus);
});
/* adjust for level 2 submenus*/
$subMenu.find('.cmp-navigation__item.cmp-navigation__item--level-2 > a').each(function() {
if($(this).closest('.cmp-navigation__item.cmp-navigation__item--level-1 .aig-submenu1').length){
$(this).closest('.cmp-navigation__item.cmp-navigation__item--level-1 .aig-submenu1').show();
//alignSubmenu(this,aigSubmenuHeight,aigSubmenuOffsetTop,subIntroStatus);
$(this).closest('.cmp-navigation__item.cmp-navigation__item--level-1 .aig-submenu1').hide();
}
});
$subMenu.removeAttr('style');
});
// Adjust the submenu2 if it move out of viewport //
$('.aig-submenu').each(function(){
const $subMenu = $(this);
$subMenu.css({visibility: 'hidden', display: 'block'});
/* adjust for level 1 submenus*/
$subMenu.find('.cmp-navigation__item.cmp-navigation__item--level-1 > a').each(function() {
//change tertiary links styling on open/close
const submenuLevel1 = $(this).closest('.cmp-navigation__item--level-1').parent();
const level1OffsetTop = submenuLevel1.offset().top;
let submenuLengthCheck = $(this).parent().children('.aig-submenu1').find("li").length > 4;
if ($(this).parent().find('.aig-submenu1').length) {
$(this).parent().children('.aig-submenu1').show();
const submenuLevel2 = $(this).parent().find('.aig-submenu1').find('.cmp-navigation__group');
const level2OffsetTop = submenuLevel2.offset().top;
const totalLevel2Height = submenuLevel2.height() + level2OffsetTop ;
const hasAlignBottom = $(this).closest('.cmp-navigation__item--level-1').hasClass('menu-align-bottom');
// Update the top position if level2 menu height greater than viewport height //
if(totalLevel2Height > $(window).height() && !hasAlignBottom && submenuLengthCheck){
$(this).parent().children('.aig-submenu1').css('top',($(window).height() - totalLevel2Height));
if(submenuLevel2.offset().top < level1OffsetTop){
$(this).parent().children('.aig-submenu1').css('top','');
}
}
$(this).parent().children('.aig-submenu1').hide();
}
});
$subMenu.removeAttr('style');
});
// To add current Iten link to submenu
$('.currentItemLink').parents('.aig-submenu1').siblings('a.active').addClass('currentItemLink');
$('.no-submenulinks').each(function(){
if($(this).find('.submenu-intro').length === 0){
$(this).find('.menu-container').css("min-height", "unset");
}
});
});
// To close Megamenu
function closeMegamenu(){
if($(this).hasClass("cmp-navigation__group") && $("body").hasClass("hide-nav-level-one")){
return false;
}
$('.aig-header .cmp-navigation__group .cmp-navigation__item > a.hover').removeClass('hover');
$('.aig-submenu').hide().attr('aria-expanded', 'false');
$('.overlay').removeClass('show');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').find('.srOnlyNavBtn.primary').removeClass('active');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').find('.srOnlyNavBtn.primary').text('+');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').find('.srOnlyNavBtn.primary').attr('aria-expanded','false');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').find('.srOnlyNavBtn.submenu').removeClass('active');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').find('.srOnlyNavBtn.submenu').text('+');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').find('.srOnlyNavBtn.submenu').attr('aria-expanded','false');
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').removeClass('hover');
$('.aig-header .cmp-navigation__group .cmp-navigation__item').find('.cmp-navigation__item-link').removeClass('active-link');
// Remove the tab-hover calss on close of hamberger menue
$('.aig-header .cmp-navigation__group .cmp-navigation__item > a.tab-hover').removeClass('tab-hover');
$('.submenu-links:not(.authored-links)').removeClass('inactive-link');
$('.submenu-links').removeClass('inactive-link');
// Hide all the submenu opened on close
$('.submenu-links:not(.authored-links) .aig-submenu1').hide();
$('.submenu-links .aig-submenu1').hide();
}
function displayMegaMenu(currElement, fromSROnylyBtn=false) {
$('.aig-submenu').hide(0);
$('.aig-header .cmp-navigation__group .cmp-navigation__item.hover').removeClass('hover');
$('.aig-submenu').attr('aria-expanded', 'false');
$('.aig-login-mobile, .aig-login-desktop').hide();
$('.overlay').removeClass('show');
if ($('.button.mobile-icon').css('display') === 'none') {
$(currElement).closest('li').find('.aig-submenu').show(0).attr('aria-expanded', 'true');
$('.aig-submenu1 .aig-submenu1').hide().attr('aria-expanded', 'false');
$(currElement).closest('li').addClass('hover');
$('.overlay').addClass('show');
}
if(fromSROnylyBtn && $(currElement).hasClass('active')){
closeMegamenu();
$(currElement).text('+');
$(currElement).attr('aria-expanded','false');
} else{
$(currElement).parent().find('.srOnlyNavBtn.primary').addClass('active');
$(currElement).parent().find('.srOnlyNavBtn.primary').text('-');
$(currElement).parent().find('.srOnlyNavBtn.primary').attr('aria-expanded','true');
}
if($(currElement).closest('li').find(".aig-submenu1 a.activeLink").length>0){ // to display selected submenu level by default other than RiskSolutions
$(currElement).closest('li').find('.cmp-navigation__item--level-1.cmp-navigation__item--active > a').trigger('mouseenter');
$(currElement).closest('li').find('.cmp-navigation__item--level-1.cmp-navigation__item--active > .srOnlyNavBtn.submenu').attr('aria-expanded','true').addClass('active').text('-');
if($(currElement).closest('li').find('.cmp-navigation__item--level-3.cmp-navigation__item--active > a.activeLink').length>0){// to display selected submenu level 2 by default other than RiskSolutions
$(currElement).closest('li').find('.cmp-navigation__item--level-2.cmp-navigation__item--active > a.active').trigger('mouseenter');
$(currElement).closest('li').find('.cmp-navigation__item--level-2.cmp-navigation__item--active > .srOnlyNavBtn.submenu').attr('aria-expanded','true').addClass('active').text('-');
}
// to display selected submenu level 2 by default other than RiskSolutions
if($(currElement).closest('li').find('.cmp-navigation__item--level-4.cmp-navigation__item--active > a.activeLink').length>0){
$(currElement).closest('li').find('.cmp-navigation__item--level-3.cmp-navigation__item--active > a.active').trigger('mouseenter');
$(currElement).closest('li').find('.cmp-navigation__item--level-3.cmp-navigation__item--active > .srOnlyNavBtn.submenu').attr('aria-expanded','true').addClass('active').text('-');
}
}
if( $(currElement).closest('li').find('.srOnlyNavBtn.submenu').hasClass('active') ){
$(currElement).closest('li').find('.srOnlyNavBtn.submenu').removeClass('active');
}
if ($(currElement).closest('li').find('.cmp-navigation__item--level-2 a.currentItemLink').length>0){ // to display submenu by default for risk solution level 2
$(currElement).closest('li').find('.cmp-navigation__item--level-1 > a.currentItemLink').trigger('mouseenter');
$(currElement).closest('li').find('.cmp-navigation__item--level-1 > a.currentItemLink').next().next().attr('aria-expanded','true').addClass('active').text('-');
}
if($(currElement).closest('li').find('.cmp-navigation__item--level-3 a.currentItemLink').length>0){// to display submenu by default for risk solution level 3
$(currElement).closest('li').find('.cmp-navigation__item--level-2 > a.currentItemLink').trigger('mouseenter');
$(currElement).closest('li').find('.cmp-navigation__item--level-2 > a.currentItemLink').next().next().attr('aria-expanded','true').addClass('active').text('-');
}
}
function displaySubMenu(currElement) {
if( $(currElement).parent().find('.srOnlyNavBtn.submenu').hasClass('active') ){
$(currElement).parent().find('.srOnlyNavBtn.submenu').removeClass('active');
$(currElement).parent().find('.srOnlyNavBtn.submenu').text('+');
$(currElement).parent().find('.srOnlyNavBtn.submenu').attr('aria-expanded','false');
$(currElement).parent().find('.aig-submenu1').first().attr('aria-expanded','false').hide();
}
else{
// Update other opened + button
let subNavBtn = $(currElement).closest("ul").find(">li").find('.srOnlyNavBtn.submenu');
subNavBtn.removeClass('active')
subNavBtn.text('+')
subNavBtn.attr('aria-expanded','false')
// Update other opened submenus in same level
$(currElement).closest('ul').find('a.active-link').removeClass('active-link');
const aigSubmenu1 = $(currElement).closest("ul").find(">li").find('.aig-submenu1');
aigSubmenu1.hide();
aigSubmenu1.attr('aria-expanded', 'false');
aigSubmenu1.removeClass('inactive-submenu');
// Update current + button
$(currElement).addClass('active');
$(currElement).text('-');
$(currElement).attr('aria-expanded','true');
$(currElement).parent().find('.cmp-navigation__item-link').first().addClass('active-link');
$(currElement).parent().find('.aig-submenu1').first().attr('aria-expanded','true').show();
}
}
function alignSubmenu(thisElement){
$(thisElement).parent().children('.aig-submenu1').css('top','').removeClass('navAlignTop');
const subIntroStatus = $('.aig-submenu').find('.submenu-intro').length !== 0 ;
let aigSubmenuHeight = $('.aig-submenu').innerHeight();
let aigSubmenuOffsetTop = $('.aig-submenu').offset().top;
const aigSubmenu1Height = $(thisElement).parent().children('.aig-submenu1').innerHeight();
const aigSubmenu1OffsetTop = $(thisElement).parent().children('.aig-submenu1').offset().top;
let totalSubmenu1Height = aigSubmenu1Height + aigSubmenu1OffsetTop;
let totalSubmenuHeight = aigSubmenuHeight + aigSubmenuOffsetTop;
if( totalSubmenu1Height > totalSubmenuHeight && subIntroStatus) {
let heightDiff = totalSubmenu1Height - totalSubmenuHeight;
if($(window).width() >= 1025){
$(thisElement).parent().children('.aig-submenu1').css('top',-heightDiff).addClass('navAlignTop');
}else{
$(thisElement).parent().children('.aig-submenu1').addClass('navAlignTop');
}
}
}
/* Function to adjust the Top position of the submenu */
function alignSubmenu(currentElmt, aigSubmenuHeight,aigSubmenuOffsetTop,subIntroStatus){
$(currentElmt).parent().children('.aig-submenu1').css('top','').removeClass('navAlignTop');
if ($(currentElmt).parent().find('.aig-submenu1').length) {
$(currentElmt).parent().children('.aig-submenu1').show();
const aigSubmenu1Height = $(currentElmt).parent().children('.aig-submenu1').outerHeight();
const aigSubmenu1OffsetTop = $(currentElmt).parent().children('.aig-submenu1').offset().top;
let totalSubmenu1Height = aigSubmenu1Height + aigSubmenu1OffsetTop;
let totalSubmenuHeight = aigSubmenuHeight + aigSubmenuOffsetTop;
let submenuLengthCheck = $(currentElmt).parent().children('.aig-submenu1').find("li").length >= 2;
if( totalSubmenu1Height > totalSubmenuHeight && subIntroStatus && submenuLengthCheck) {
let heightDiff;
if($(window).width() >= 1280){
heightDiff = totalSubmenu1Height - totalSubmenuHeight - 30;
$(currentElmt).parent().children('.aig-submenu1').css('top',-heightDiff).addClass('navAlignTop');
}else if($(window).width() >= 1025 && $(window).width() <= 1279){
heightDiff = totalSubmenu1Height - totalSubmenuHeight - 45;
$(currentElmt).parent().children('.aig-submenu1').css('top',-heightDiff).addClass('navAlignTop');
}else{
}
}
$(currentElmt).parent().children('.aig-submenu1').hide();
}
}
$('.hashlink').on("click", function(){
$('.button.mobile-icon button').trigger('click');
$('.overlay').removeClass('show');
$('.cmp-navigation__item--active a').removeClass('tab-hover');
$('.overlay, .right-nav-container, .headernavigation').removeClass('show');
$('.button.mobile-icon').removeClass('close');
$('.overlay').removeClass('sm-show');
})
/* Navigation JS - END */
//Desktop login functionality start
$(function() {
$('.right-nav-container .cmp-container .button.aig-login-button:not(.search-button)').click(function(){
// To close Mega menu
closeMegamenu();
$('.aig-login-mobile, .aig-login-desktop').css('display','block');
$('.overlay').addClass('show');
});
// close button functionality
$('#login-close').find('.cmp-button').click(function(){
$('.aig-login-mobile, .aig-login-desktop').hide();
$('.overlay').removeClass('show');
});
});
//Desktop login functionality end
//Mobile login functionality
$(function(){
if(window.matchMedia('(max-width: 960px)').matches){
$('.right-nav-container .cmp-container .button.aig-login-button:not(.search-button)').click(function(){
$('.aig-login-mobile.dialog').addClass('display-content');
// for mobile sliding animation
$('.aig-login-mobile').addClass('login-slide');
$('.aig-login-mobile.dialog').removeClass('hide-content');
if($('body').hasClass('hide-nav-level-one')){
$('.back-to-nav-btn').trigger("click");
}
});
// for mobile sliding hiding
$('.aig-login-mobile .cmp-container .text:first .cmp-text').click(function(){
$('.aig-login-mobile').removeClass('login-slide');
$('.aig-login-mobile.dialog').removeClass('display-content');
$('.aig-login-mobile.dialog').addClass('hide-content');
});
}
});
//Mobile login functionality ends
//Login screen hide functionality on hover of overlay starts here
$(function() {
$('.overlay').hover(function(){
//hide desktop
$('.aig-login-desktop').hide();
});
});
//Login screen hide functionality on hover of overlay ends here
/*
_ _ _ _
___| (_) ___| | __ (_)___
/ __| | |/ __| |/ / | / __|
\__ \ | | (__| < _ | \__ \
|___/_|_|\___|_|\_(_)/ |___/
|__/
Version: 1.8.1
Author: Ken Wheeler
Website: http://kenwheeler.github.io
Docs: http://kenwheeler.github.io/slick
Repo: http://github.com/kenwheeler/slick
Issues: http://github.com/kenwheeler/slick/issues
*/
/* global window, document, define, jQuery, setInterval, clearInterval */
;(function(factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports !== 'undefined') {
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(function($) {
let Slick = window.Slick || {};
Slick = (function() {
let instanceUid = 0;
function slick(element, settings) {
let _ = this, dataSettings;
_.defaults = {
accessibility: true,
adaptiveHeight: true,
appendArrows: $(element),
appendDots: $(element),
arrows: true,
asNavFor: null,
prevArrow: 'Previous ',
nextArrow: 'Next ',
autoplay: false,
autoplaySpeed: 3000,
centerMode: false,
centerPadding: '50px',
cssEase: 'ease',
customPaging: function(slider, i) {
return $(' ').text(i + 1);
},
dots: false,
dotsClass: 'slick-dots',
draggable: true,
easing: 'linear',
edgeFriction: 0.35,
fade: false,
focusOnSelect: false,
focusOnChange: false,
infinite: true,
initialSlide: 0,
lazyLoad: 'ondemand',
mobileFirst: false,
pauseOnHover: true,
pauseOnFocus: true,
pauseOnDotsHover: false,
respondTo: 'window',
responsive: null,
rows: 1,
rtl: false,
slide: '',
slidesPerRow: 1,
slidesToShow: 1,
slidesToScroll: 1,
speed: 500,
swipe: true,
swipeToSlide: false,
touchMove: true,
touchThreshold: 5,
useCSS: true,
useTransform: true,
variableWidth: false,
variableHeight: false,
vertical: false,
verticalSwiping: false,
waitForAnimate: true,
zIndex: 1000
};
_.initials = {
animating: false,
dragging: false,
autoPlayTimer: null,
currentDirection: 0,
currentLeft: null,
currentSlide: 0,
direction: 1,
$dots: null,
listWidth: null,
listHeight: null,
loadIndex: 0,
$nextArrow: null,
$prevArrow: null,
scrolling: false,
slideCount: null,
slideWidth: null,
$slideTrack: null,
$slides: null,
sliding: false,
slideOffset: 0,
swipeLeft: null,
swiping: false,
$list: null,
touchObject: {},
transformsEnabled: false,
unslicked: false
};
$.extend(_, _.initials);
_.activeBreakpoint = null;
_.animType = null;
_.animProp = null;
_.breakpoints = [];
_.breakpointSettings = [];
_.cssTransitions = false;
_.focussed = false;
_.interrupted = false;
_.hidden = 'hidden';
_.paused = true;
_.positionProp = null;
_.respondTo = null;
_.rowCount = 1;
_.shouldClick = true;
_.$slider = $(element);
_.$slidesCache = null;
_.transformType = null;
_.transitionType = null;
_.visibilityChange = 'visibilitychange';
_.windowWidth = 0;
_.windowTimer = null;
dataSettings = $(element).data('slick') || {};
_.options = $.extend({}, _.defaults, settings, dataSettings);
_.currentSlide = _.options.initialSlide;
_.originalSettings = _.options;
if (typeof document.mozHidden !== 'undefined') {
_.hidden = 'mozHidden';
_.visibilityChange = 'mozvisibilitychange';
} else if (typeof document.webkitHidden !== 'undefined') {
_.hidden = 'webkitHidden';
_.visibilityChange = 'webkitvisibilitychange';
}
_.autoPlay = $.proxy(_.autoPlay, _);
_.autoPlayClear = $.proxy(_.autoPlayClear, _);
_.autoPlayIterator = $.proxy(_.autoPlayIterator, _);
_.changeSlide = $.proxy(_.changeSlide, _);
_.clickHandler = $.proxy(_.clickHandler, _);
_.selectHandler = $.proxy(_.selectHandler, _);
_.setPosition = $.proxy(_.setPosition, _);
_.swipeHandler = $.proxy(_.swipeHandler, _);
_.dragHandler = $.proxy(_.dragHandler, _);
_.keyHandler = $.proxy(_.keyHandler, _);
_.instanceUid = instanceUid++;
// A simple way to check for HTML strings
// Strict HTML recognition (must start with <)
// Extracted from jQuery v1.11 source
_.htmlExpr = /^(?:\s*(<[\w\W]+>)[^>]*)$/;
_.registerBreakpoints();
_.init(true);
}
return slick;
}());
Slick.prototype.activateADA = function() {
let _ = this;
if(_.$slideTrack){
_.$slideTrack.find('.slick-active').attr({
'aria-hidden': 'false'
}).find('a, input, button, select').attr({
'tabindex': '0'
});
}
};
Slick.prototype.addSlide = Slick.prototype.slickAdd = function(markup, index, addBefore) {
let _ = this;
if (typeof(index) === 'boolean') {
addBefore = index;
index = null;
} else if (index < 0 || (index >= _.slideCount)) {
return false;
}
_.unload();
if (typeof(index) === 'number') {
if (index === 0 && _.$slides.length === 0) {
$(markup).appendTo(_.$slideTrack);
} else if (addBefore) {
$(markup).insertBefore(_.$slides.eq(index));
} else {
$(markup).insertAfter(_.$slides.eq(index));
}
} else {
if (addBefore === true) {
$(markup).prependTo(_.$slideTrack);
} else {
$(markup).appendTo(_.$slideTrack);
}
}
_.$slides = _.$slideTrack.children(this.options.slide);
_.$slideTrack.children(this.options.slide).detach();
_.$slideTrack.append(_.$slides);
_.$slides.each(function(index, element) {
$(element).attr('data-slick-index', index);
});
_.$slidesCache = _.$slides;
_.reinit();
};
Slick.prototype.animateHeight = function() {
let _ = this;
if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) {
let targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true);
_.$list.animate({
height: targetHeight
}, _.options.speed);
}
};
Slick.prototype.animateSlide = function(targetLeft, callback) {
let animProps = {},
_ = this;
_.animateHeight();
if (_.options.rtl === true && _.options.vertical === false) {
targetLeft = -targetLeft;
}
if (_.transformsEnabled === false) {
if (_.options.vertical === false) {
_.$slideTrack.animate({
left: targetLeft
}, _.options.speed, _.options.easing, callback);
} else {
_.$slideTrack.animate({
top: targetLeft
}, _.options.speed, _.options.easing, callback);
}
} else {
if (_.cssTransitions === false) {
if (_.options.rtl === true) {
_.currentLeft = -(_.currentLeft);
}
$({
animStart: _.currentLeft
}).animate({
animStart: targetLeft
}, {
duration: _.options.speed,
easing: _.options.easing,
step: function(now) {
now = Math.ceil(now);
if (_.options.vertical === false) {
animProps[_.animType] = 'translate(' +
now + 'px, 0px)';
_.$slideTrack.css(animProps);
} else {
animProps[_.animType] = 'translate(0px,' +
now + 'px)';
_.$slideTrack.css(animProps);
}
},
complete: function() {
if (callback) {
callback.call();
}
}
});
} else {
_.applyTransition();
targetLeft = Math.ceil(targetLeft);
if (_.options.vertical === false) {
animProps[_.animType] = 'translate3d(' + targetLeft + 'px, 0px, 0px)';
} else {
animProps[_.animType] = 'translate3d(0px,' + targetLeft + 'px, 0px)';
}
_.$slideTrack.css(animProps);
if (callback) {
setTimeout(function() {
_.disableTransition();
callback.call();
}, _.options.speed);
}
}
}
};
Slick.prototype.getNavTarget = function() {
let _ = this,
asNavFor = _.options.asNavFor;
if ( asNavFor && asNavFor != null ) {
asNavFor = $(asNavFor).not(_.$slider);
}
return asNavFor;
};
Slick.prototype.asNavFor = function(index) {
let _ = this,
asNavFor = _.getNavTarget();
if ( asNavFor !== null && typeof asNavFor === 'object' ) {
asNavFor.each(function() {
let target = $(this).slick('getSlick');
if(!target.unslicked) {
target.slideHandler(index, true);
}
});
}
};
Slick.prototype.applyTransition = function(slide) {
let _ = this,
transition = {};
if (_.options.fade === false) {
transition[_.transitionType] = _.transformType + ' ' + _.options.speed + 'ms ' + _.options.cssEase;
} else {
transition[_.transitionType] = 'opacity ' + _.options.speed + 'ms ' + _.options.cssEase;
}
if (_.options.fade === false) {
_.$slideTrack.css(transition);
} else {
_.$slides.eq(slide).css(transition);
}
};
Slick.prototype.autoPlay = function() {
let _ = this;
_.autoPlayClear();
if ( _.slideCount > _.options.slidesToShow ) {
_.autoPlayTimer = setInterval( _.autoPlayIterator, _.options.autoplaySpeed );
}
};
Slick.prototype.autoPlayClear = function() {
let _ = this;
if (_.autoPlayTimer) {
clearInterval(_.autoPlayTimer);
}
};
Slick.prototype.autoPlayIterator = function() {
let _ = this,
slideTo = _.currentSlide + _.options.slidesToScroll;
if ( !_.paused && !_.interrupted && !_.focussed ) {
if ( _.options.infinite === false ) {
if ( _.direction === 1 && ( _.currentSlide + 1 ) === ( _.slideCount - 1 )) {
_.direction = 0;
}
else if ( _.direction === 0 ) {
slideTo = _.currentSlide - _.options.slidesToScroll;
if ( _.currentSlide - 1 === 0 ) {
_.direction = 1;
}
}
}
_.slideHandler( slideTo );
}
};
Slick.prototype.buildArrows = function() {
let _ = this;
if (_.options.arrows === true ) {
_.$prevArrow = $(_.options.prevArrow).addClass('slick-arrow');
_.$nextArrow = $(_.options.nextArrow).addClass('slick-arrow');
if( _.slideCount > _.options.slidesToShow ) {
_.$prevArrow.removeClass('slick-hidden').removeAttr('aria-hidden tabindex');
_.$nextArrow.removeClass('slick-hidden').removeAttr('aria-hidden tabindex');
if (_.htmlExpr.test(_.options.prevArrow)) {
_.$prevArrow.prependTo(_.options.appendArrows);
}
if (_.htmlExpr.test(_.options.nextArrow)) {
_.$nextArrow.appendTo(_.options.appendArrows);
}
if (_.options.infinite !== true) {
_.$prevArrow
.addClass('slick-disabled')
.attr('aria-disabled', 'true');
}
} else {
_.$prevArrow.add( _.$nextArrow )
.addClass('slick-hidden')
.attr({
'aria-disabled': 'true',
'tabindex': '-1'
});
}
}
};
Slick.prototype.buildDots = function() {
let _ = this, i, dot;
if (_.options.dots === true && _.slideCount > _.options.slidesToShow) {
_.$slider.addClass('slick-dotted');
dot = $('').addClass(_.options.dotsClass);
for (i = 0; i <= _.getDotCount(); i += 1) {
dot.append($(' ').append(_.options.customPaging.call(this, _, i)));
}
_.$dots = dot.appendTo(_.options.appendDots);
_.$dots.find('li').first().addClass('slick-active');
}
};
Slick.prototype.buildOut = function() {
let _ = this;
_.$slides =
_.$slider
.children( _.options.slide + ':not(.slick-cloned)')
.addClass('slick-slide');
_.slideCount = _.$slides.length;
_.$slides.each(function(index, element) {
$(element)
.attr('data-slick-index', index)
.data('originalStyling', $(element).attr('style') || '');
});
_.$slider.addClass('slick-slider');
_.$slideTrack = (_.slideCount === 0) ?
$('
').appendTo(_.$slider) :
_.$slides.wrapAll('
').parent();
_.$list = _.$slideTrack.wrap(
'
').parent();
_.$slideTrack.css('opacity', 0);
if (_.options.centerMode === true || _.options.swipeToSlide === true) {
_.options.slidesToScroll = 1;
}
$('img[data-lazy]', _.$slider).not('[src]').addClass('slick-loading');
_.setupInfinite();
_.buildArrows();
_.buildDots();
_.updateDots();
_.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0);
if (_.options.draggable === true) {
_.$list.addClass('draggable');
}
};
Slick.prototype.buildRows = function() {
let _ = this, a, b, c, newSlides, numOfSlides, originalSlides,slidesPerSection;
newSlides = document.createDocumentFragment();
originalSlides = _.$slider.children();
if(_.options.rows > 0) {
slidesPerSection = _.options.slidesPerRow * _.options.rows;
numOfSlides = Math.ceil(
originalSlides.length / slidesPerSection
);
for(a = 0; a < numOfSlides; a++){
let slide = document.createElement('div');
for(b = 0; b < _.options.rows; b++) {
let row = document.createElement('div');
for(c = 0; c < _.options.slidesPerRow; c++) {
let target = (a * slidesPerSection + ((b * _.options.slidesPerRow) + c));
if (originalSlides.get(target)) {
row.appendChild(originalSlides.get(target));
}
}
slide.appendChild(row);
}
newSlides.appendChild(slide);
}
_.$slider.empty().append(newSlides);
_.$slider.children().children().children()
.css({
'width':(100 / _.options.slidesPerRow) + '%',
'display': 'inline-block'
});
}
};
Slick.prototype.checkResponsive = function(initial, forceUpdate) {
let _ = this, breakpoint, targetBreakpoint, respondToWidth, triggerBreakpoint = false;
let sliderWidth = _.$slider.width();
let windowWidth = window.innerWidth || $(window).width();
if (_.respondTo === 'window') {
respondToWidth = windowWidth;
} else if (_.respondTo === 'slider') {
respondToWidth = sliderWidth;
} else if (_.respondTo === 'min') {
respondToWidth = Math.min(windowWidth, sliderWidth);
}
if ( _.options.responsive &&
_.options.responsive.length &&
_.options.responsive !== null) {
targetBreakpoint = null;
for (breakpoint in _.breakpoints) {
if (_.breakpoints.hasOwnProperty(breakpoint)) {
if (_.originalSettings.mobileFirst === false) {
if (respondToWidth < _.breakpoints[breakpoint]) {
targetBreakpoint = _.breakpoints[breakpoint];
}
} else {
if (respondToWidth > _.breakpoints[breakpoint]) {
targetBreakpoint = _.breakpoints[breakpoint];
}
}
}
}
if (targetBreakpoint !== null) {
if (_.activeBreakpoint !== null) {
if (targetBreakpoint !== _.activeBreakpoint || forceUpdate) {
_.activeBreakpoint =
targetBreakpoint;
if (_.breakpointSettings[targetBreakpoint] === 'unslick') {
_.unslick(targetBreakpoint);
} else {
_.options = $.extend({}, _.originalSettings,
_.breakpointSettings[
targetBreakpoint]);
if (initial === true) {
_.currentSlide = _.options.initialSlide;
}
_.refresh(initial);
}
triggerBreakpoint = targetBreakpoint;
}
} else {
_.activeBreakpoint = targetBreakpoint;
if (_.breakpointSettings[targetBreakpoint] === 'unslick') {
_.unslick(targetBreakpoint);
} else {
_.options = $.extend({}, _.originalSettings,
_.breakpointSettings[
targetBreakpoint]);
if (initial === true) {
_.currentSlide = _.options.initialSlide;
}
_.refresh(initial);
}
triggerBreakpoint = targetBreakpoint;
}
} else {
if (_.activeBreakpoint !== null) {
_.activeBreakpoint = null;
_.options = _.originalSettings;
if (initial === true) {
_.currentSlide = _.options.initialSlide;
}
_.refresh(initial);
triggerBreakpoint = targetBreakpoint;
}
}
// only trigger breakpoints during an actual break. not on initialize.
if( !initial && triggerBreakpoint !== false ) {
_.$slider.trigger('breakpoint', [_, triggerBreakpoint]);
}
}
};
Slick.prototype.changeSlide = function(event, dontAnimate) {
let _ = this,
$target = $(event.currentTarget),
indexOffset, slideOffset, unevenOffset;
// If target is a link, prevent default action.
if($target.is('a')) {
event.preventDefault();
}
// If target is not the element (ie: a child), find the .
if(!$target.is('li')) {
$target = $target.closest('li');
}
unevenOffset = (_.slideCount % _.options.slidesToScroll !== 0);
indexOffset = unevenOffset ? 0 : (_.slideCount - _.currentSlide) % _.options.slidesToScroll;
switch (event.data.message) {
case 'previous':
slideOffset = indexOffset === 0 ? _.options.slidesToScroll : _.options.slidesToShow - indexOffset;
if (_.slideCount > _.options.slidesToShow) {
_.slideHandler(_.currentSlide - slideOffset, false, dontAnimate);
}
break;
case 'next':
slideOffset = indexOffset === 0 ? _.options.slidesToScroll : indexOffset;
if (_.slideCount > _.options.slidesToShow) {
_.slideHandler(_.currentSlide + slideOffset, false, dontAnimate);
}
break;
case 'index':
let index = event.data.index === 0 ? 0 :
event.data.index || $target.index() * _.options.slidesToScroll;
_.slideHandler(_.checkNavigable(index), false, dontAnimate);
$target.children().trigger('focus');
break;
default:
return;
}
};
Slick.prototype.checkNavigable = function(index) {
let _ = this,
navigables, prevNavigable;
navigables = _.getNavigableIndexes();
prevNavigable = 0;
if (index > navigables[navigables.length - 1]) {
index = navigables[navigables.length - 1];
} else {
for (let n in navigables) {
if (index < navigables[n]) {
index = prevNavigable;
break;
}
prevNavigable = navigables[n];
}
}
return index;
};
Slick.prototype.cleanUpEvents = function() {
let _ = this;
if (_.options.dots && _.$dots !== null) {
$('li', _.$dots)
.off('click.slick', _.changeSlide)
.off('mouseenter.slick', $.proxy(_.interrupt, _, true))
.off('mouseleave.slick', $.proxy(_.interrupt, _, false));
if (_.options.accessibility === true) {
_.$dots.off('keydown.slick', _.keyHandler);
}
}
_.$slider.off('focus.slick blur.slick');
if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
_.$prevArrow && _.$prevArrow.off('click.slick', _.changeSlide);
_.$nextArrow && _.$nextArrow.off('click.slick', _.changeSlide);
if (_.options.accessibility === true) {
_.$prevArrow && _.$prevArrow.off('keydown.slick', _.keyHandler);
_.$nextArrow && _.$nextArrow.off('keydown.slick', _.keyHandler);
}
}
_.$list.off('touchstart.slick mousedown.slick', _.swipeHandler);
_.$list.off('touchmove.slick mousemove.slick', _.swipeHandler);
_.$list.off('touchend.slick mouseup.slick', _.swipeHandler);
_.$list.off('touchcancel.slick mouseleave.slick', _.swipeHandler);
_.$list.off('click.slick', _.clickHandler);
$(document).off(_.visibilityChange, _.visibility);
_.cleanUpSlideEvents();
if (_.options.accessibility === true) {
_.$list.off('keydown.slick', _.keyHandler);
}
if (_.options.focusOnSelect === true) {
$(_.$slideTrack).children().off('click.slick', _.selectHandler);
}
$(window).off('orientationchange.slick.slick-' + _.instanceUid, _.orientationChange);
$(window).off('resize.slick.slick-' + _.instanceUid, _.resize);
$('[draggable!=true]', _.$slideTrack).off('dragstart', _.preventDefault);
$(window).off('load.slick.slick-' + _.instanceUid, _.setPosition);
};
Slick.prototype.cleanUpSlideEvents = function() {
let _ = this;
_.$list.off('mouseenter.slick', $.proxy(_.interrupt, _, true));
_.$list.off('mouseleave.slick', $.proxy(_.interrupt, _, false));
};
Slick.prototype.cleanUpRows = function() {
let _ = this, originalSlides;
if(_.options.rows > 0) {
originalSlides = _.$slides.children().children();
originalSlides.removeAttr('style');
_.$slider.empty().append(originalSlides);
}
};
Slick.prototype.clickHandler = function(event) {
let _ = this;
if (_.shouldClick === false) {
event.stopImmediatePropagation();
event.stopPropagation();
event.preventDefault();
}
};
Slick.prototype.destroy = function(refresh) {
let _ = this;
_.autoPlayClear();
_.touchObject = {};
_.cleanUpEvents();
$('.slick-cloned', _.$slider).detach();
if (_.$dots) {
_.$dots.remove();
}
if ( _.$prevArrow && _.$prevArrow.length ) {
_.$prevArrow
.removeClass('slick-disabled slick-arrow slick-hidden')
.removeAttr('aria-hidden aria-disabled tabindex')
.css('display','');
if ( _.htmlExpr.test( _.options.prevArrow )) {
_.$prevArrow.remove();
}
}
if ( _.$nextArrow && _.$nextArrow.length ) {
_.$nextArrow
.removeClass('slick-disabled slick-arrow slick-hidden')
.removeAttr('aria-hidden aria-disabled tabindex')
.css('display','');
if ( _.htmlExpr.test( _.options.nextArrow )) {
_.$nextArrow.remove();
}
}
if (_.$slides) {
_.$slides
.removeClass('slick-slide slick-active slick-center slick-visible slick-current')
.removeAttr('aria-hidden')
.removeAttr('data-slick-index')
.each(function(){
$(this).attr('style', $(this).data('originalStyling'));
});
_.$slideTrack.children(this.options.slide).detach();
_.$slideTrack.detach();
_.$list.detach();
_.$slider.append(_.$slides);
}
_.cleanUpRows();
_.$slider.removeClass('slick-slider');
_.$slider.removeClass('slick-initialized');
_.$slider.removeClass('slick-dotted');
_.unslicked = true;
if(!refresh) {
_.$slider.trigger('destroy', [_]);
}
};
Slick.prototype.disableTransition = function(slide) {
let _ = this,
transition = {};
transition[_.transitionType] = '';
if (_.options.fade === false) {
_.$slideTrack.css(transition);
} else {
_.$slides.eq(slide).css(transition);
}
};
Slick.prototype.fadeSlide = function(slideIndex, callback) {
let _ = this;
if (_.cssTransitions === false) {
_.$slides.eq(slideIndex).css({
zIndex: _.options.zIndex
});
_.$slides.eq(slideIndex).animate({
opacity: 1
}, _.options.speed, _.options.easing, callback);
} else {
_.applyTransition(slideIndex);
_.$slides.eq(slideIndex).css({
opacity: 1,
zIndex: _.options.zIndex
});
if (callback) {
setTimeout(function() {
_.disableTransition(slideIndex);
callback.call();
}, _.options.speed);
}
}
};
Slick.prototype.fadeSlideOut = function(slideIndex) {
let _ = this;
if (_.cssTransitions === false) {
_.$slides.eq(slideIndex).animate({
opacity: 0,
zIndex: _.options.zIndex - 2
}, _.options.speed, _.options.easing);
} else {
_.applyTransition(slideIndex);
_.$slides.eq(slideIndex).css({
opacity: 0,
zIndex: _.options.zIndex - 2
});
}
};
Slick.prototype.filterSlides = Slick.prototype.slickFilter = function(filter) {
let _ = this;
if (filter !== null) {
_.$slidesCache = _.$slides;
_.unload();
_.$slideTrack.children(this.options.slide).detach();
_.$slidesCache.filter(filter).appendTo(_.$slideTrack);
_.reinit();
}
};
Slick.prototype.focusHandler = function() {
let _ = this;
// If any child element receives focus within the slider we need to pause the autoplay
_.$slider
.off('focus.slick blur.slick')
.on(
'focus.slick',
'*',
function(event) {
let $sf = $(this);
setTimeout(function() {
if( _.options.pauseOnFocus ) {
if ($sf.is(':focus')) {
_.focussed = true;
_.autoPlay();
}
}
}, 0);
}
).on(
'blur.slick',
'*',
function(event) {
// When a blur occurs on any elements within the slider we become unfocused
if( _.options.pauseOnFocus ) {
_.focussed = false;
_.autoPlay();
}
}
);
};
Slick.prototype.getCurrent = Slick.prototype.slickCurrentSlide = function() {
let _ = this;
return _.currentSlide;
};
Slick.prototype.getDotCount = function() {
let _ = this;
let breakPoint = 0;
let counter = 0;
let pagerQty = 0;
if (_.options.infinite === true) {
if (_.slideCount <= _.options.slidesToShow) {
++pagerQty;
} else {
while (breakPoint < _.slideCount) {
++pagerQty;
breakPoint = counter + _.options.slidesToScroll;
counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow;
}
}
} else if (_.options.centerMode === true) {
pagerQty = _.slideCount;
} else if(!_.options.asNavFor) {
pagerQty = 1 + Math.ceil((_.slideCount - _.options.slidesToShow) / _.options.slidesToScroll);
}else {
while (breakPoint < _.slideCount) {
++pagerQty;
breakPoint = counter + _.options.slidesToScroll;
counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow;
}
}
return pagerQty - 1;
};
Slick.prototype.getLeft = function(slideIndex) {
let _ = this,
targetLeft,
verticalHeight,
verticalOffset = 0,
targetSlide,
coef;
_.slideOffset = 0;
verticalHeight = _.$slides.first().outerHeight(true);
if (_.options.infinite === true) {
if (_.slideCount > _.options.slidesToShow) {
_.slideOffset = (_.slideWidth * _.options.slidesToShow) * -1;
coef = -1;
if (_.options.vertical === true && _.options.centerMode === true) {
if (_.options.slidesToShow === 2) {
coef = -1.5;
} else if (_.options.slidesToShow === 1) {
coef = -2;
}
}
verticalOffset = (verticalHeight * _.options.slidesToShow) * coef;
}
if (_.slideCount % _.options.slidesToScroll !== 0) {
if (slideIndex + _.options.slidesToScroll > _.slideCount && _.slideCount > _.options.slidesToShow) {
if (slideIndex > _.slideCount) {
_.slideOffset = ((_.options.slidesToShow - (slideIndex - _.slideCount)) * _.slideWidth) * -1;
verticalOffset = ((_.options.slidesToShow - (slideIndex - _.slideCount)) * verticalHeight) * -1;
} else {
_.slideOffset = ((_.slideCount % _.options.slidesToScroll) * _.slideWidth) * -1;
verticalOffset = ((_.slideCount % _.options.slidesToScroll) * verticalHeight) * -1;
}
}
}
} else {
if (slideIndex + _.options.slidesToShow > _.slideCount) {
_.slideOffset = ((slideIndex + _.options.slidesToShow) - _.slideCount) * _.slideWidth;
verticalOffset = ((slideIndex + _.options.slidesToShow) - _.slideCount) * verticalHeight;
}
}
if (_.slideCount <= _.options.slidesToShow) {
_.slideOffset = 0;
verticalOffset = 0;
}
if (_.options.centerMode === true && _.slideCount <= _.options.slidesToShow) {
_.slideOffset = ((_.slideWidth * Math.floor(_.options.slidesToShow)) / 2) - ((_.slideWidth * _.slideCount) / 2);
} else if (_.options.centerMode === true && _.options.infinite === true) {
_.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth;
} else if (_.options.centerMode === true) {
_.slideOffset = 0;
_.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2);
}
if (_.options.vertical === false) {
targetLeft = ((slideIndex * _.slideWidth) * -1) + _.slideOffset;
} else {
targetLeft = ((slideIndex * verticalHeight) * -1) + verticalOffset;
}
if (_.options.variableWidth === true) {
if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) {
targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex);
} else {
targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow);
}
if (_.options.rtl === true) {
if (targetSlide[0]) {
targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1;
} else {
targetLeft = 0;
}
} else {
targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0;
}
if (_.options.centerMode === true) {
if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) {
targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex);
} else {
targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow + 1);
}
if (_.options.rtl === true) {
if (targetSlide[0]) {
targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1;
} else {
targetLeft = 0;
}
} else {
targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0;
}
targetLeft += (_.$list.width() - targetSlide.outerWidth()) / 2;
}
}
return targetLeft;
};
Slick.prototype.getOption = Slick.prototype.slickGetOption = function(option) {
let _ = this;
return _.options[option];
};
Slick.prototype.getNavigableIndexes = function() {
let _ = this,
breakPoint = 0,
counter = 0,
indexes = [],
max;
if (_.options.infinite === false) {
max = _.slideCount;
} else {
breakPoint = _.options.slidesToScroll * -1;
counter = _.options.slidesToScroll * -1;
max = _.slideCount * 2;
}
while (breakPoint < max) {
indexes.push(breakPoint);
breakPoint = counter + _.options.slidesToScroll;
counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow;
}
return indexes;
};
Slick.prototype.getSlick = function() {
return this;
};
Slick.prototype.getSlideCount = function() {
let _ = this,
slidesTraversed, swipedSlide, swipeTarget, centerOffset;
centerOffset = _.options.centerMode === true ? Math.floor(_.$list.width() / 2) : 0;
swipeTarget = (_.swipeLeft * -1) + centerOffset;
if (_.options.swipeToSlide === true) {
_.$slideTrack.find('.slick-slide').each(function(index, slide) {
let slideOuterWidth, slideOffset, slideRightBoundary;
slideOuterWidth = $(slide).outerWidth();
slideOffset = slide.offsetLeft;
if (_.options.centerMode !== true) {
slideOffset += (slideOuterWidth / 2);
}
slideRightBoundary = slideOffset + (slideOuterWidth);
if (swipeTarget < slideRightBoundary) {
swipedSlide = slide;
return false;
}
});
slidesTraversed = Math.abs($(swipedSlide).attr('data-slick-index') - _.currentSlide) || 1;
return slidesTraversed;
} else {
return _.options.slidesToScroll;
}
};
Slick.prototype.goTo = Slick.prototype.slickGoTo = function(slide, dontAnimate) {
let _ = this;
_.changeSlide({
data: {
message: 'index',
index: parseInt(slide, 10)
}
}, dontAnimate);
};
Slick.prototype.init = function(creation) {
let _ = this;
if (!$(_.$slider).hasClass('slick-initialized')) {
$(_.$slider).addClass('slick-initialized');
_.buildRows();
_.buildOut();
_.setProps();
_.startLoad();
_.loadSlider();
_.initializeEvents();
_.updateArrows();
_.updateDots();
_.checkResponsive(true);
_.focusHandler();
}
if (creation) {
_.$slider.trigger('init', [_]);
}
if (_.options.accessibility === true) {
_.initADA();
}
if ( _.options.autoplay ) {
_.paused = false;
_.autoPlay();
}
};
Slick.prototype.initADA = function() {
let _ = this,
numDotGroups = Math.ceil(_.slideCount / _.options.slidesToScroll),
tabControlIndexes = _.getNavigableIndexes().filter(function(val) {
return (val >= 0) && (val < _.slideCount);
});
if(_.$slides){
_.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({
'aria-hidden': 'true',
'tabindex': '-1'
}).find('a, input, button, select').attr({
'tabindex': '-1'
});
}
if (_.$dots !== null) {
_.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) {
let slideControlIndex = tabControlIndexes.indexOf(i);
$(this).attr({
'role': 'tabpanel',
'id': 'slick-slide' + _.instanceUid + i,
'tabindex': -1
});
if (slideControlIndex !== -1) {
let ariaButtonControl = 'slick-slide-control' + _.instanceUid + slideControlIndex;
if ($('#' + ariaButtonControl).length) {
$(this).attr({
'aria-describedby': ariaButtonControl
});
}
}
});
_.$dots.attr('role', 'tablist').find('li').each(function(i) {
let mappedSlideIndex = tabControlIndexes[i];
$(this).attr({
'role': 'presentation'
});
$(this).find('button').first().attr({
'role': 'tab',
'id': 'slick-slide-control' + _.instanceUid + i,
'aria-controls': 'slick-slide' + _.instanceUid + mappedSlideIndex,
'aria-label': (i + 1) + ' of ' + numDotGroups
});
}).end();
}
if(_.$slides){
for (let i=_.currentSlide, max=i+_.options.slidesToShow; i < max; i++) {
if (_.options.focusOnChange) {
_.$slides.eq(i).attr({'tabindex': '0'});
} else {
_.$slides.eq(i).removeAttr('tabindex');
}
}
}
_.activateADA();
};
Slick.prototype.initArrowEvents = function() {
let _ = this;
if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
_.$prevArrow
.off('click.slick')
.on('click.slick', {
message: 'previous'
}, _.changeSlide);
_.$nextArrow
.off('click.slick')
.on('click.slick', {
message: 'next'
}, _.changeSlide);
if (_.options.accessibility === true) {
_.$prevArrow.on('keydown.slick', _.keyHandler);
_.$nextArrow.on('keydown.slick', _.keyHandler);
}
}
};
Slick.prototype.initDotEvents = function() {
let _ = this;
if (_.options.dots === true && _.slideCount > _.options.slidesToShow) {
$('li', _.$dots).on('click.slick', {
message: 'index'
}, _.changeSlide);
if (_.options.accessibility === true) {
_.$dots.on('keydown.slick', _.keyHandler);
}
}
if (_.options.dots === true && _.options.pauseOnDotsHover === true && _.slideCount > _.options.slidesToShow) {
$('li', _.$dots)
.on('mouseenter.slick', $.proxy(_.interrupt, _, true))
.on('mouseleave.slick', $.proxy(_.interrupt, _, false));
}
};
Slick.prototype.initSlideEvents = function() {
let _ = this;
if ( _.options.pauseOnHover ) {
_.$list.on('mouseenter.slick', $.proxy(_.interrupt, _, true));
_.$list.on('mouseleave.slick', $.proxy(_.interrupt, _, false));
}
};
Slick.prototype.initializeEvents = function() {
let _ = this;
_.initArrowEvents();
_.initDotEvents();
_.initSlideEvents();
_.$list.on('touchstart.slick mousedown.slick', {
action: 'start'
}, _.swipeHandler);
_.$list.on('touchmove.slick mousemove.slick', {
action: 'move'
}, _.swipeHandler);
_.$list.on('touchend.slick mouseup.slick', {
action: 'end'
}, _.swipeHandler);
_.$list.on('touchcancel.slick mouseleave.slick', {
action: 'end'
}, _.swipeHandler);
_.$list.on('click.slick', _.clickHandler);
$(document).on(_.visibilityChange, $.proxy(_.visibility, _));
if (_.options.accessibility === true) {
_.$list.on('keydown.slick', _.keyHandler);
}
if (_.options.focusOnSelect === true) {
$(_.$slideTrack).children().on('click.slick', _.selectHandler);
}
$(window).on('orientationchange.slick.slick-' + _.instanceUid, $.proxy(_.orientationChange, _));
$(window).on('resize.slick.slick-' + _.instanceUid, $.proxy(_.resize, _));
$('[draggable!=true]', _.$slideTrack).on('dragstart', _.preventDefault);
$(window).on('load.slick.slick-' + _.instanceUid, _.setPosition);
$(_.setPosition);
};
Slick.prototype.initUI = function() {
let _ = this;
if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
_.$prevArrow.show();
_.$nextArrow.show();
}
if (_.options.dots === true && _.slideCount > _.options.slidesToShow) {
_.$dots.show();
}
};
Slick.prototype.keyHandler = function(event) {
let _ = this;
//Dont slide if the cursor is inside the form fields and arrow keys are pressed
if(!event.target.tagName.match('TEXTAREA|INPUT|SELECT')) {
if (event.keyCode === 37 && _.options.accessibility === true) {
_.changeSlide({
data: {
message: _.options.rtl === true ? 'next' : 'previous'
}
});
} else if (event.keyCode === 39 && _.options.accessibility === true) {
_.changeSlide({
data: {
message: _.options.rtl === true ? 'previous' : 'next'
}
});
}
}
};
Slick.prototype.lazyLoad = function() {
let _ = this,
loadRange, cloneRange, rangeStart, rangeEnd;
function loadImages(imagesScope) {
$('img[data-lazy]', imagesScope).each(function() {
let image = $(this),
imageSource = $(this).attr('data-lazy'),
imageSrcSet = $(this).attr('data-srcset'),
imageSizes = $(this).attr('data-sizes') || _.$slider.attr('data-sizes'),
imageToLoad = document.createElement('img');
imageToLoad.onload = function() {
image
.animate({ opacity: 0 }, 100, function() {
if (imageSrcSet) {
image
.attr('srcset', imageSrcSet );
if (imageSizes) {
image
.attr('sizes', imageSizes );
}
}
image
.attr('src', imageSource)
.animate({ opacity: 1 }, 200, function() {
image
.removeAttr('data-lazy data-srcset data-sizes')
.removeClass('slick-loading');
});
_.$slider.trigger('lazyLoaded', [_, image, imageSource]);
});
};
imageToLoad.onerror = function() {
image
.removeAttr( 'data-lazy' )
.removeClass( 'slick-loading' )
.addClass( 'slick-lazyload-error' );
_.$slider.trigger('lazyLoadError', [ _, image, imageSource ]);
};
imageToLoad.src = imageSource;
});
}
if (_.options.centerMode === true) {
if (_.options.infinite === true) {
rangeStart = _.currentSlide + (_.options.slidesToShow / 2 + 1);
rangeEnd = rangeStart + _.options.slidesToShow + 2;
} else {
rangeStart = Math.max(0, _.currentSlide - (_.options.slidesToShow / 2 + 1));
rangeEnd = 2 + (_.options.slidesToShow / 2 + 1) + _.currentSlide;
}
} else {
rangeStart = _.options.infinite ? _.options.slidesToShow + _.currentSlide : _.currentSlide;
rangeEnd = Math.ceil(rangeStart + _.options.slidesToShow);
if (_.options.fade === true) {
if (rangeStart > 0) rangeStart--;
if (rangeEnd <= _.slideCount) rangeEnd++;
}
}
loadRange = _.$slider.find('.slick-slide').slice(rangeStart, rangeEnd);
if (_.options.lazyLoad === 'anticipated') {
let prevSlide = rangeStart - 1,
nextSlide = rangeEnd,
$slides = _.$slider.find('.slick-slide');
for (let i = 0; i < _.options.slidesToScroll; i++) {
if (prevSlide < 0) prevSlide = _.slideCount - 1;
loadRange = loadRange.add($slides.eq(prevSlide));
loadRange = loadRange.add($slides.eq(nextSlide));
prevSlide--;
nextSlide++;
}
}
loadImages(loadRange);
if (_.slideCount <= _.options.slidesToShow) {
cloneRange = _.$slider.find('.slick-slide');
loadImages(cloneRange);
} else
if (_.currentSlide >= _.slideCount - _.options.slidesToShow) {
cloneRange = _.$slider.find('.slick-cloned').slice(0, _.options.slidesToShow);
loadImages(cloneRange);
} else if (_.currentSlide === 0) {
cloneRange = _.$slider.find('.slick-cloned').slice(_.options.slidesToShow * -1);
loadImages(cloneRange);
}
};
Slick.prototype.loadSlider = function() {
let _ = this;
_.setPosition();
_.$slideTrack.css({
opacity: 1
});
_.$slider.removeClass('slick-loading');
_.initUI();
if (_.options.lazyLoad === 'progressive') {
_.progressiveLazyLoad();
}
};
Slick.prototype.next = Slick.prototype.slickNext = function() {
let _ = this;
_.changeSlide({
data: {
message: 'next'
}
});
};
Slick.prototype.orientationChange = function() {
let _ = this;
_.checkResponsive();
_.setPosition();
};
Slick.prototype.pause = Slick.prototype.slickPause = function() {
let _ = this;
_.autoPlayClear();
_.paused = true;
};
Slick.prototype.play = Slick.prototype.slickPlay = function() {
let _ = this;
_.autoPlay();
_.options.autoplay = true;
_.paused = false;
_.focussed = false;
_.interrupted = false;
};
Slick.prototype.postSlide = function(index) {
let _ = this;
if( !_.unslicked ) {
_.$slider.trigger('afterChange', [_, index]);
_.animating = false;
if (_.slideCount > _.options.slidesToShow) {
_.setPosition();
}
_.swipeLeft = null;
if ( _.options.autoplay ) {
_.autoPlay();
}
if (_.options.accessibility === true) {
_.initADA();
if (_.options.focusOnChange) {
let $currentSlide = $(_.$slides.get(_.currentSlide));
$currentSlide.attr('tabindex', 0).focus();
}
}
}
};
Slick.prototype.prev = Slick.prototype.slickPrev = function() {
let _ = this;
_.changeSlide({
data: {
message: 'previous'
}
});
};
Slick.prototype.preventDefault = function(event) {
event.preventDefault();
};
Slick.prototype.progressiveLazyLoad = function( tryCount ) {
tryCount = tryCount || 1;
let _ = this,
$imgsToLoad = $( 'img[data-lazy]', _.$slider ),
image,
imageSource,
imageSrcSet,
imageSizes,
imageToLoad;
if ( $imgsToLoad.length ) {
image = $imgsToLoad.first();
imageSource = image.attr('data-lazy');
imageSrcSet = image.attr('data-srcset');
imageSizes = image.attr('data-sizes') || _.$slider.attr('data-sizes');
imageToLoad = document.createElement('img');
imageToLoad.onload = function() {
if (imageSrcSet) {
image
.attr('srcset', imageSrcSet );
if (imageSizes) {
image
.attr('sizes', imageSizes );
}
}
image
.attr( 'src', imageSource )
.removeAttr('data-lazy data-srcset data-sizes')
.removeClass('slick-loading');
if ( _.options.adaptiveHeight === true ) {
_.setPosition();
}
_.$slider.trigger('lazyLoaded', [ _, image, imageSource ]);
_.progressiveLazyLoad();
};
imageToLoad.onerror = function() {
if ( tryCount < 3 ) {
/**
* try to load the image 3 times,
* leave a slight delay so we don't get
* servers blocking the request.
*/
setTimeout( function() {
_.progressiveLazyLoad( tryCount + 1 );
}, 500 );
} else {
image
.removeAttr( 'data-lazy' )
.removeClass( 'slick-loading' )
.addClass( 'slick-lazyload-error' );
_.$slider.trigger('lazyLoadError', [ _, image, imageSource ]);
_.progressiveLazyLoad();
}
};
imageToLoad.src = imageSource;
} else {
_.$slider.trigger('allImagesLoaded', [ _ ]);
}
};
Slick.prototype.refresh = function( initializing ) {
let _ = this, currentSlide, lastVisibleIndex;
lastVisibleIndex = _.slideCount - _.options.slidesToShow;
// in non-infinite sliders, we don't want to go past the
// last visible index.
if( !_.options.infinite && ( _.currentSlide > lastVisibleIndex )) {
_.currentSlide = lastVisibleIndex;
}
// if less slides than to show, go to start.
if ( _.slideCount <= _.options.slidesToShow ) {
_.currentSlide = 0;
}
currentSlide = _.currentSlide;
_.destroy(true);
$.extend(_, _.initials, { currentSlide: currentSlide });
_.init();
if( !initializing ) {
_.changeSlide({
data: {
message: 'index',
index: currentSlide
}
}, false);
}
};
Slick.prototype.registerBreakpoints = function() {
let _ = this, breakpoint, currentBreakpoint, l,
responsiveSettings = _.options.responsive || null;
if ( $.type(responsiveSettings) === 'array' && responsiveSettings ) {
_.respondTo = _.options.respondTo || 'window';
for ( breakpoint in responsiveSettings ) {
l = _.breakpoints.length-1;
if (responsiveSettings.hasOwnProperty(breakpoint)) {
currentBreakpoint = responsiveSettings[breakpoint].breakpoint;
// loop through the breakpoints and cut out any existing
// ones with the same breakpoint number, we don't want dupes.
while( l >= 0 ) {
if( _.breakpoints[l] && _.breakpoints[l] === currentBreakpoint ) {
_.breakpoints.splice(l,1);
}
l--;
}
_.breakpoints.push(currentBreakpoint);
_.breakpointSettings[currentBreakpoint] = responsiveSettings[breakpoint].settings;
}
}
_.breakpoints.sort(function(a, b) {
return ( _.options.mobileFirst ) ? a-b : b-a;
});
}
};
Slick.prototype.reinit = function() {
let _ = this;
_.$slides =
_.$slideTrack
.children(_.options.slide)
.addClass('slick-slide');
_.slideCount = _.$slides.length;
if (_.currentSlide >= _.slideCount && _.currentSlide !== 0) {
_.currentSlide = _.currentSlide - _.options.slidesToScroll;
}
if (_.slideCount <= _.options.slidesToShow) {
_.currentSlide = 0;
}
_.registerBreakpoints();
_.setProps();
_.setupInfinite();
_.buildArrows();
_.updateArrows();
_.initArrowEvents();
_.buildDots();
_.updateDots();
_.initDotEvents();
_.cleanUpSlideEvents();
_.initSlideEvents();
_.checkResponsive(false, true);
if (_.options.focusOnSelect === true) {
$(_.$slideTrack).children().on('click.slick', _.selectHandler);
}
_.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0);
_.setPosition();
_.focusHandler();
_.paused = !_.options.autoplay;
_.autoPlay();
_.$slider.trigger('reInit', [_]);
};
Slick.prototype.resize = function() {
let _ = this;
if ($(window).width() !== _.windowWidth) {
clearTimeout(_.windowDelay);
_.windowDelay = window.setTimeout(function() {
_.windowWidth = $(window).width();
_.checkResponsive();
if( !_.unslicked ) { _.setPosition(); }
}, 50);
}
};
Slick.prototype.removeSlide = Slick.prototype.slickRemove = function(index, removeBefore, removeAll) {
let _ = this;
if (typeof(index) === 'boolean') {
removeBefore = index;
index = removeBefore === true ? 0 : _.slideCount - 1;
} else {
index = removeBefore === true ? --index : index;
}
if (_.slideCount < 1 || index < 0 || index > _.slideCount - 1) {
return false;
}
_.unload();
if (removeAll === true) {
_.$slideTrack.children().remove();
} else {
_.$slideTrack.children(this.options.slide).eq(index).remove();
}
_.$slides = _.$slideTrack.children(this.options.slide);
_.$slideTrack.children(this.options.slide).detach();
_.$slideTrack.append(_.$slides);
_.$slidesCache = _.$slides;
_.reinit();
};
Slick.prototype.setCSS = function(position) {
let _ = this,
positionProps = {},
x, y;
if (_.options.rtl === true) {
position = -position;
}
x = _.positionProp === 'left' ? Math.ceil(position) + 'px' : '0px';
y = _.positionProp === 'top' ? Math.ceil(position) + 'px' : '0px';
positionProps[_.positionProp] = position;
if (_.transformsEnabled === false) {
_.$slideTrack.css(positionProps);
} else {
positionProps = {};
if (_.cssTransitions === false) {
positionProps[_.animType] = 'translate(' + x + ', ' + y + ')';
_.$slideTrack.css(positionProps);
} else {
positionProps[_.animType] = 'translate3d(' + x + ', ' + y + ', 0px)';
_.$slideTrack.css(positionProps);
}
}
};
Slick.prototype.setDimensions = function() {
let _ = this;
if (_.options.vertical === false) {
if (_.options.centerMode === true) {
_.$list.css({
padding: ('0px ' + _.options.centerPadding)
});
}
} else {
_.$list.height(_.$slides.first().outerHeight(true) * _.options.slidesToShow);
if (_.options.centerMode === true) {
_.$list.css({
padding: (_.options.centerPadding + ' 0px')
});
}
}
_.listWidth = _.$list.width();
_.listHeight = _.$list.height();
if (_.options.vertical === false && _.options.variableWidth === false) {
_.slideWidth = Math.ceil(_.listWidth / _.options.slidesToShow);
_.$slideTrack.width(Math.ceil((_.slideWidth * _.$slideTrack.children('.slick-slide').length)));
} else if (_.options.variableWidth === true) {
_.$slideTrack.width(5000 * _.slideCount);
} else {
_.slideWidth = Math.ceil(_.listWidth);
_.$slideTrack.height(Math.ceil((_.$slides.first().outerHeight(true) * _.$slideTrack.children('.slick-slide').length)));
}
let offset = _.$slides.first().outerWidth(true) - _.$slides.first().width();
if (_.options.variableWidth === false) _.$slideTrack.children('.slick-slide').width(_.slideWidth - offset);
};
Slick.prototype.setFade = function() {
let _ = this,
targetLeft;
_.$slides.each(function(index, element) {
targetLeft = (_.slideWidth * index) * -1;
if (_.options.rtl === true) {
$(element).css({
position: 'relative',
right: targetLeft,
top: 0,
zIndex: _.options.zIndex - 2,
opacity: 0
});
} else {
$(element).css({
position: 'relative',
left: targetLeft,
top: 0,
zIndex: _.options.zIndex - 2,
opacity: 0
});
}
});
_.$slides.eq(_.currentSlide).css({
zIndex: _.options.zIndex - 1,
opacity: 1
});
};
Slick.prototype.setHeight = function() {
let _ = this;
if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) {
let targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true);
_.$list.css('height', targetHeight);
}
};
Slick.prototype.setOption =
Slick.prototype.slickSetOption = function() {
/**
* accepts arguments in format of:
*
* - for changing a single option's value:
* .slick("setOption", option, value, refresh )
*
* - for changing a set of responsive options:
* .slick("setOption", 'responsive', [{}, ...], refresh )
*
* - for updating multiple values at once (not responsive)
* .slick("setOption", { 'option': value, ... }, refresh )
*/
let _ = this, l, item, option, value, refresh = false, type;
if( $.type( arguments[0] ) === 'object' ) {
option = arguments[0];
refresh = arguments[1];
type = 'multiple';
} else if ( $.type( arguments[0] ) === 'string' ) {
option = arguments[0];
value = arguments[1];
refresh = arguments[2];
if ( arguments[0] === 'responsive' && $.type( arguments[1] ) === 'array' ) {
type = 'responsive';
} else if ( typeof arguments[1] !== 'undefined' ) {
type = 'single';
}
}
if ( type === 'single' ) {
_.options[option] = value;
} else if ( type === 'multiple' ) {
$.each( option , function( opt, val ) {
_.options[opt] = val;
});
} else if ( type === 'responsive' ) {
for ( item in value ) {
if( $.type( _.options.responsive ) !== 'array' ) {
_.options.responsive = [ value[item] ];
} else {
l = _.options.responsive.length-1;
// loop through the responsive object and splice out duplicates.
while( l >= 0 ) {
if( _.options.responsive[l].breakpoint === value[item].breakpoint ) {
_.options.responsive.splice(l,1);
}
l--;
}
_.options.responsive.push( value[item] );
}
}
}
if ( refresh ) {
_.unload();
_.reinit();
}
};
Slick.prototype.setPosition = function() {
let _ = this;
_.setDimensions();
_.setHeight();
if (_.options.fade === false) {
_.setCSS(_.getLeft(_.currentSlide));
} else {
_.setFade();
}
_.$slider.trigger('setPosition', [_]);
};
Slick.prototype.setProps = function() {
let _ = this,
bodyStyle = document.body.style;
_.positionProp = _.options.vertical === true ? 'top' : 'left';
if (_.positionProp === 'top') {
_.$slider.addClass('slick-vertical');
} else {
_.$slider.removeClass('slick-vertical');
}
if (bodyStyle.WebkitTransition !== undefined ||
bodyStyle.MozTransition !== undefined ||
bodyStyle.msTransition !== undefined) {
if (_.options.useCSS === true) {
_.cssTransitions = true;
}
}
if ( _.options.fade ) {
if ( typeof _.options.zIndex === 'number' ) {
if( _.options.zIndex < 3 ) {
_.options.zIndex = 3;
}
} else {
_.options.zIndex = _.defaults.zIndex;
}
}
if (bodyStyle.OTransform !== undefined) {
_.animType = 'OTransform';
_.transformType = '-o-transform';
_.transitionType = 'OTransition';
if (bodyStyle.perspectiveProperty === undefined && bodyStyle.webkitPerspective === undefined) _.animType = false;
}
if (bodyStyle.MozTransform !== undefined) {
_.animType = 'MozTransform';
_.transformType = '-moz-transform';
_.transitionType = 'MozTransition';
if (bodyStyle.perspectiveProperty === undefined && bodyStyle.MozPerspective === undefined) _.animType = false;
}
if (bodyStyle.webkitTransform !== undefined) {
_.animType = 'webkitTransform';
_.transformType = '-webkit-transform';
_.transitionType = 'webkitTransition';
if (bodyStyle.perspectiveProperty === undefined && bodyStyle.webkitPerspective === undefined) _.animType = false;
}
if (bodyStyle.msTransform !== undefined) {
_.animType = 'msTransform';
_.transformType = '-ms-transform';
_.transitionType = 'msTransition';
if (bodyStyle.msTransform === undefined) _.animType = false;
}
if (bodyStyle.transform !== undefined && _.animType !== false) {
_.animType = 'transform';
_.transformType = 'transform';
_.transitionType = 'transition';
}
_.transformsEnabled = _.options.useTransform && (_.animType !== null && _.animType !== false);
};
Slick.prototype.setSlideClasses = function(index) {
let _ = this,
centerOffset, allSlides, indexOffset, remainder;
allSlides = _.$slider
.find('.slick-slide')
.removeClass('slick-active slick-center slick-current')
.attr('aria-hidden', 'true');
_.$slides
.eq(index)
.addClass('slick-current');
if (_.options.centerMode === true) {
let evenCoef = _.options.slidesToShow % 2 === 0 ? 1 : 0;
centerOffset = Math.floor(_.options.slidesToShow / 2);
if (_.options.infinite === true) {
if (index >= centerOffset && index <= (_.slideCount - 1) - centerOffset) {
_.$slides
.slice(index - centerOffset + evenCoef, index + centerOffset + 1)
.addClass('slick-active')
.attr('aria-hidden', 'false');
} else {
indexOffset = _.options.slidesToShow + index;
allSlides
.slice(indexOffset - centerOffset + 1 + evenCoef, indexOffset + centerOffset + 2)
.addClass('slick-active')
.attr('aria-hidden', 'false');
}
if (index === 0) {
allSlides
.eq( _.options.slidesToShow + _.slideCount + 1 )
.addClass('slick-center');
} else if (index === _.slideCount - 1) {
allSlides
.eq(_.options.slidesToShow)
.addClass('slick-center');
}
}
_.$slides
.eq(index)
.addClass('slick-center');
} else {
if (index >= 0 && index <= (_.slideCount - _.options.slidesToShow)) {
_.$slides
.slice(index, index + _.options.slidesToShow)
.addClass('slick-active')
.attr('aria-hidden', 'false');
} else if (allSlides.length <= _.options.slidesToShow) {
allSlides
.addClass('slick-active')
.attr('aria-hidden', 'false');
} else {
remainder = _.slideCount % _.options.slidesToShow;
indexOffset = _.options.infinite === true ? _.options.slidesToShow + index : index;
if (_.options.slidesToShow === _.options.slidesToScroll && (_.slideCount - index) < _.options.slidesToShow) {
allSlides
.slice(indexOffset - (_.options.slidesToShow - remainder), indexOffset + remainder)
.addClass('slick-active')
.attr('aria-hidden', 'false');
} else {
allSlides
.slice(indexOffset, indexOffset + _.options.slidesToShow)
.addClass('slick-active')
.attr('aria-hidden', 'false');
}
}
}
if (_.options.lazyLoad === 'ondemand' || _.options.lazyLoad === 'anticipated') {
_.lazyLoad();
}
};
Slick.prototype.setupInfinite = function() {
let _ = this,
i, slideIndex, infiniteCount;
if (_.options.fade === true) {
_.options.centerMode = false;
}
if (_.options.infinite === true && _.options.fade === false) {
slideIndex = null;
if (_.slideCount > _.options.slidesToShow) {
if (_.options.centerMode === true) {
infiniteCount = _.options.slidesToShow + 1;
} else {
infiniteCount = _.options.slidesToShow;
}
for (i = _.slideCount; i > (_.slideCount -
infiniteCount); i -= 1) {
slideIndex = i - 1;
$(_.$slides[slideIndex]).clone(true).attr('id', '')
.attr('data-slick-index', slideIndex - _.slideCount)
.prependTo(_.$slideTrack).addClass('slick-cloned');
}
for (i = 0; i < infiniteCount + _.slideCount; i += 1) {
slideIndex = i;
$(_.$slides[slideIndex]).clone(true).attr('id', '')
.attr('data-slick-index', slideIndex + _.slideCount)
.appendTo(_.$slideTrack).addClass('slick-cloned');
}
_.$slideTrack.find('.slick-cloned').find('[id]').each(function() {
$(this).attr('id', '');
});
}
}
};
Slick.prototype.interrupt = function( toggle ) {
let _ = this;
if( !toggle ) {
_.autoPlay();
}
_.interrupted = toggle;
};
Slick.prototype.selectHandler = function(event) {
let _ = this;
let targetElement =
$(event.target).is('.slick-slide') ?
$(event.target) :
$(event.target).parents('.slick-slide');
let index = parseInt(targetElement.attr('data-slick-index'), 10);
if (!index) index = 0;
if (_.slideCount <= _.options.slidesToShow) {
_.slideHandler(index, false, true);
return;
}
_.slideHandler(index);
};
Slick.prototype.slideHandler = function(index, sync, dontAnimate) {
let targetSlide, animSlide, oldSlide, slideLeft, targetLeft = null,
_ = this, navTarget;
sync = sync || false;
if (_.animating === true && _.options.waitForAnimate === true) {
return;
}
if (_.options.fade === true && _.currentSlide === index) {
return;
}
if (sync === false) {
_.asNavFor(index);
}
targetSlide = index;
targetLeft = _.getLeft(targetSlide);
slideLeft = _.getLeft(_.currentSlide);
_.currentLeft = _.swipeLeft === null ? slideLeft : _.swipeLeft;
if (_.options.infinite === false && _.options.centerMode === false && (index < 0 || index > _.getDotCount() * _.options.slidesToScroll)) {
if (_.options.fade === false) {
targetSlide = _.currentSlide;
if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) {
_.animateSlide(slideLeft, function() {
_.postSlide(targetSlide);
});
} else {
_.postSlide(targetSlide);
}
}
return;
} else if (_.options.infinite === false && _.options.centerMode === true && (index < 0 || index > (_.slideCount - _.options.slidesToScroll))) {
if (_.options.fade === false) {
targetSlide = _.currentSlide;
if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) {
_.animateSlide(slideLeft, function() {
_.postSlide(targetSlide);
});
} else {
_.postSlide(targetSlide);
}
}
return;
}
if ( _.options.autoplay ) {
clearInterval(_.autoPlayTimer);
}
if (targetSlide < 0) {
if (_.slideCount % _.options.slidesToScroll !== 0) {
animSlide = _.slideCount - (_.slideCount % _.options.slidesToScroll);
} else {
animSlide = _.slideCount + targetSlide;
}
} else if (targetSlide >= _.slideCount) {
if (_.slideCount % _.options.slidesToScroll !== 0) {
animSlide = 0;
} else {
animSlide = targetSlide - _.slideCount;
}
} else {
animSlide = targetSlide;
}
_.animating = true;
_.$slider.trigger('beforeChange', [_, _.currentSlide, animSlide]);
oldSlide = _.currentSlide;
_.currentSlide = animSlide;
_.setSlideClasses(_.currentSlide);
if ( _.options.asNavFor ) {
navTarget = _.getNavTarget();
navTarget = navTarget.slick('getSlick');
if ( navTarget.slideCount <= navTarget.options.slidesToShow ) {
navTarget.setSlideClasses(_.currentSlide);
}
}
_.updateDots();
_.updateArrows();
if (_.options.fade === true) {
if (dontAnimate !== true) {
_.fadeSlideOut(oldSlide);
_.fadeSlide(animSlide, function() {
_.postSlide(animSlide);
});
} else {
_.postSlide(animSlide);
}
_.animateHeight();
return;
}
if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) {
_.animateSlide(targetLeft, function() {
_.postSlide(animSlide);
});
} else {
_.postSlide(animSlide);
}
};
Slick.prototype.startLoad = function() {
let _ = this;
if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) {
_.$prevArrow.hide();
_.$nextArrow.hide();
}
if (_.options.dots === true && _.slideCount > _.options.slidesToShow) {
_.$dots.hide();
}
_.$slider.addClass('slick-loading');
};
Slick.prototype.swipeDirection = function() {
let xDist, yDist, r, swipeAngle, _ = this;
xDist = _.touchObject.startX - _.touchObject.curX;
yDist = _.touchObject.startY - _.touchObject.curY;
r = Math.atan2(yDist, xDist);
swipeAngle = Math.round(r * 180 / Math.PI);
if (swipeAngle < 0) {
swipeAngle = 360 - Math.abs(swipeAngle);
}
if ((swipeAngle <= 45) && (swipeAngle >= 0)) {
return (_.options.rtl === false ? 'left' : 'right');
}
if ((swipeAngle <= 360) && (swipeAngle >= 315)) {
return (_.options.rtl === false ? 'left' : 'right');
}
if ((swipeAngle >= 135) && (swipeAngle <= 225)) {
return (_.options.rtl === false ? 'right' : 'left');
}
if (_.options.verticalSwiping === true) {
if ((swipeAngle >= 35) && (swipeAngle <= 135)) {
return 'down';
} else {
return 'up';
}
}
return 'vertical';
};
Slick.prototype.swipeEnd = function(event) {
let _ = this,
slideCount,
direction;
_.dragging = false;
_.swiping = false;
if (_.scrolling) {
_.scrolling = false;
return false;
}
_.interrupted = false;
_.shouldClick = ( _.touchObject.swipeLength > 10 ) ? false : true;
if ( _.touchObject.curX === undefined ) {
return false;
}
if ( _.touchObject.edgeHit === true ) {
_.$slider.trigger('edge', [_, _.swipeDirection() ]);
}
if ( _.touchObject.swipeLength >= _.touchObject.minSwipe ) {
direction = _.swipeDirection();
switch ( direction ) {
case 'left':
case 'down':
slideCount =
_.options.swipeToSlide ?
_.checkNavigable( _.currentSlide + _.getSlideCount() ) :
_.currentSlide + _.getSlideCount();
_.currentDirection = 0;
break;
case 'right':
case 'up':
slideCount =
_.options.swipeToSlide ? _.checkNavigable( _.currentSlide - _.getSlideCount() ) : _.currentSlide - _.getSlideCount();
_.currentDirection = 1;
break;
default:
}
if( direction !== 'vertical' ) {
_.slideHandler( slideCount );
_.touchObject = {};
_.$slider.trigger('swipe', [_, direction ]);
}
} else {
if ( _.touchObject.startX !== _.touchObject.curX ) {
_.slideHandler( _.currentSlide );
_.touchObject = {};
}
}
};
Slick.prototype.swipeHandler = function(event) {
let _ = this;
if ((_.options.swipe === false) || ('ontouchend' in document && _.options.swipe === false)) {
return;
} else if (_.options.draggable === false && event.type.indexOf('mouse') !== -1) {
return;
}
_.touchObject.fingerCount = event.originalEvent && event.originalEvent.touches !== undefined ? event.originalEvent.touches.length : 1;
_.touchObject.minSwipe = _.listWidth / _.options .touchThreshold;
if (_.options.verticalSwiping === true) {
_.touchObject.minSwipe = _.listHeight / _.options .touchThreshold;
}
switch (event.data.action) {
case 'start':
_.swipeStart(event);
break;
case 'move':
_.swipeMove(event);
break;
case 'end':
_.swipeEnd(event);
break;
}
};
Slick.prototype.swipeMove = function(event) {
let _ = this, edgeWasHit = false, curLeft, swipeDirection, swipeLength, positionOffset, touches, verticalSwipeLength;
touches = event.originalEvent !== undefined ? event.originalEvent.touches : null;
if (!_.dragging || _.scrolling || touches && touches.length !== 1) {
return false;
}
curLeft = _.getLeft(_.currentSlide);
_.touchObject.curX = touches !== undefined ? touches[0].pageX : event.clientX;
_.touchObject.curY = touches !== undefined ? touches[0].pageY : event.clientY;
_.touchObject.swipeLength = Math.round(Math.sqrt(Math.pow(_.touchObject.curX - _.touchObject.startX, 2)));
verticalSwipeLength = Math.round(Math.sqrt(Math.pow(_.touchObject.curY - _.touchObject.startY, 2)));
if (!_.options.verticalSwiping && !_.swiping && verticalSwipeLength > 4) {
_.scrolling = true;
return false;
}
if (_.options.verticalSwiping === true) {
_.touchObject.swipeLength = verticalSwipeLength;
}
swipeDirection = _.swipeDirection();
if (event.originalEvent !== undefined && _.touchObject.swipeLength > 4) {
_.swiping = true;
event.preventDefault();
}
positionOffset = (_.options.rtl === false ? 1 : -1) * (_.touchObject.curX > _.touchObject.startX ? 1 : -1);
if (_.options.verticalSwiping === true) {
positionOffset = _.touchObject.curY > _.touchObject.startY ? 1 : -1;
}
swipeLength = _.touchObject.swipeLength;
_.touchObject.edgeHit = false;
if (_.options.infinite === false) {
if ((_.currentSlide === 0 && swipeDirection === 'right') || (_.currentSlide >= _.getDotCount() && swipeDirection === 'left')) {
swipeLength = _.touchObject.swipeLength * _.options.edgeFriction;
_.touchObject.edgeHit = true;
}
}
if (_.options.vertical === false) {
_.swipeLeft = curLeft + swipeLength * positionOffset;
} else {
_.swipeLeft = curLeft + (swipeLength * (_.$list.height() / _.listWidth)) * positionOffset;
}
if (_.options.verticalSwiping === true) {
_.swipeLeft = curLeft + swipeLength * positionOffset;
}
if (_.options.fade === true || _.options.touchMove === false) {
return false;
}
if (_.animating === true) {
_.swipeLeft = null;
return false;
}
_.setCSS(_.swipeLeft);
};
Slick.prototype.swipeStart = function(event) {
let _ = this, touches;
_.interrupted = true;
if (_.touchObject.fingerCount !== 1 || _.slideCount <= _.options.slidesToShow) {
_.touchObject = {};
return false;
}
if (event.originalEvent !== undefined && event.originalEvent.touches !== undefined) {
touches = event.originalEvent.touches[0];
}
_.touchObject.startX = _.touchObject.curX = touches !== undefined ? touches.pageX : event.clientX;
_.touchObject.startY = _.touchObject.curY = touches !== undefined ? touches.pageY : event.clientY;
_.dragging = true;
};
Slick.prototype.unfilterSlides = Slick.prototype.slickUnfilter = function() {
let _ = this;
if (_.$slidesCache !== null) {
_.unload();
_.$slideTrack.children(this.options.slide).detach();
_.$slidesCache.appendTo(_.$slideTrack);
_.reinit();
}
};
Slick.prototype.unload = function() {
let _ = this;
$('.slick-cloned', _.$slider).remove();
if (_.$dots) {
_.$dots.remove();
}
if (_.$prevArrow && _.htmlExpr.test(_.options.prevArrow)) {
_.$prevArrow.remove();
}
if (_.$nextArrow && _.htmlExpr.test(_.options.nextArrow)) {
_.$nextArrow.remove();
}
_.$slides.removeClass('slick-slide slick-active slick-visible slick-current').attr('aria-hidden', 'true').css('width', '');
};
Slick.prototype.unslick = function(fromBreakpoint) {
let _ = this;
_.$slider.trigger('unslick', [_, fromBreakpoint]);
_.destroy();
};
Slick.prototype.updateArrows = function() {
let _ = this;
if ( _.options.arrows === true &&
_.slideCount > _.options.slidesToShow &&
!_.options.infinite ) {
_.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
_.$nextArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
if (_.currentSlide === 0) {
_.$prevArrow.addClass('slick-disabled').attr('aria-disabled', 'true');
_.$nextArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
} else if (_.currentSlide >= _.slideCount - _.options.slidesToShow && _.options.centerMode === false) {
_.$nextArrow.addClass('slick-disabled').attr('aria-disabled', 'true');
_.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
} else if (_.currentSlide >= _.slideCount - 1 && _.options.centerMode === true) {
_.$nextArrow.addClass('slick-disabled').attr('aria-disabled', 'true');
_.$prevArrow.removeClass('slick-disabled').attr('aria-disabled', 'false');
}
}
};
Slick.prototype.updateDots = function() {
let _ = this;
if (_.$dots !== null) {
_.$dots.find('li').removeClass('slick-active').find('button').attr({'aria-selected': 'false', 'tab-index': '-1'}).end();
_.$dots.find('li').eq(Math.floor(_.currentSlide / _.options.slidesToScroll)).addClass('slick-active').find('button').attr({'aria-selected': 'true', 'tab-index': '0'});
}
};
Slick.prototype.visibility = function() {
let _ = this;
if ( _.options.autoplay ) {
if ( document[_.hidden] ) {
_.interrupted = true;
} else {
_.interrupted = false;
}
}
};
$.fn.slick = function() {
let _ = this, opt = arguments[0], args = Array.prototype.slice.call(arguments, 1), l = _.length, i, ret;
for (i = 0; i < l; i++) {
if (typeof opt == 'object' || typeof opt == 'undefined')
_[i].slick = new Slick(_[i], opt);
else
ret = _[i].slick[opt].apply(_[i].slick, args);
if (typeof ret != 'undefined') return ret;
}
return _;
};
}));
/* AIG Caraousel Method - START */
$(document).ready(function() {
aigCarousel();
if ($('.thumbnail-photo-gallery').find('.tab-card-column')) {
$('.thumbnail-photo-gallery').addClass('tab-card-height');
}
});
function aigCarousel(){
$('.aig-carousel').not('.timeline-dialog-carousel').each(function(){
const $this = $(this);
let noOfItem = 4;
let noOfItemTablet = 3;
let noOfItemMobile = 1;
let noOfItemMobilesmall = 1;
let arrows = true;
let dots = true;
// To find AIG Product card
const hasAIgProduct = $this.find('.aig-productcard');
const hasAIgArticleCard = $this.find('.aig-article-card');
const hasAIgAwardCard = $this.find('.aig-award-card');
const hasAIgNewsRelease = $this.find('.aig-news-release');
const hasAIgFaeturedJobsCard = $this.find('.aig-featured-job');
const hasAIgAnnualCard = $this.find('.aig-annual-card');
const hasAIgLinkedInCard = $this.find('.aig-linkedin-card');
const hasAIGDownloadCard= $this.find('.aig-download-card');
const hasAIgPhotoPanel = $this.find('.aig-photo-panel');
const hasAIgInstagram = $this.find('.aig-instagram-card');
const hasThreeColumn = $this.hasClass('aig-carousel-3-col');
const hasOneColumn = $this.hasClass('aig-carousel-1-col');
const hasTimeline = $this.find('.aig-timeline-carousel');
if(hasAIgProduct.length || hasAIgArticleCard.length || hasAIgAwardCard.length || hasThreeColumn){
noOfItem = 3;
}
if(hasOneColumn){
noOfItem = 1;
noOfItemTablet = 1;
}
if(hasAIgProduct.length){
noOfItem = 3;
noOfItemTablet = 2;
}
if (hasTimeline.length) {
noOfItem = 3;
noOfItemTablet = 3;
noOfItemMobile = 1;
arrows = true;
dots = false;
}
if (hasAIgFaeturedJobsCard.length) {
noOfItem = 3;
noOfItemTablet = 2;
arrows = false;
}
if(hasAIGDownloadCard.length || hasAIgInstagram.length){
noOfItem = 3;
noOfItemTablet = 3;
arrows = true;
}
if(hasAIgLinkedInCard.length || hasAIgNewsRelease.length || hasAIgInstagram.length){
noOfItem = 3;
noOfItemTablet = 2;
arrows = true;
}
if(hasAIgAnnualCard.length){
noOfItem = 3;
noOfItemTablet = 3;
arrows = true;
}
if (hasAIgPhotoPanel.length) {
noOfItem = 6;
noOfItemTablet = 4;
noOfItemMobile = 3;
noOfItemMobilesmall = 2;
arrows = true;
}
// To hide thumbnails when button is present
if($this.parent().find('.aig-carousel + .button.aig_button').length) {
$this.addClass('hide-thumbnails');
}
//dynamically add class to carousel outer container
const cardClasses = ['aig-claims-card','aig-featured-job','aig-article-card','aig-award-card','aig-news-release','aig-download-card','aig-annual-card','aig-photo-panel','aig-instagram-card','aig-timeline-carousel'];
for (const i in cardClasses) {
if($this.find('.'+cardClasses[i]).length) {
if(cardClasses[i] === 'aig-annual-card' || cardClasses[i] === 'aig-award-card' || cardClasses[i] === 'aig-featured-job'){
$this.parent().closest('.container').addClass(cardClasses[i]+'-container');
}
else{
$this.parents('.container').addClass(cardClasses[i]+'-container');
}
}
}
// To add slick method
$('> .cmp-container > div', $this).slick({
//setting accessibility to true for ADA compliance
accessibility: true,
//setting to show prev/next buttons
adaptiveHeight: true,
//setting to show card height
arrows: arrows,
// setting thumbnail visibility to true
dots: dots,
//setting looping to infinite looping
infinite: false,
//setting transition speed for carousel
speed: 300,
//setting then number of slides to be displayed
slidesToShow: noOfItem,
//setting then number of slides to be scrolled at a time
slidesToScroll: noOfItem,
responsive: [{
//1st breakpoint at 1024px
breakpoint: 1024,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: noOfItemTablet, slidesToScroll: noOfItemTablet, dots: dots
}
}, {
//3rd breakpoint at 768px
breakpoint: 768,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: noOfItemMobile, slidesToScroll: noOfItemMobile
}
}, {
//4th breakpoint at 480px
breakpoint: 480,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: noOfItemMobilesmall, slidesToScroll: noOfItemMobilesmall
}
}]
});
// To add slick method for Tab Component
$('> .cmp-tabs > ol', $this).slick({
accessibility: true, arrows: arrows,dots: false,infinite: false,speed: 300,slidesToShow: 5,slidesToScroll: 5,
responsive: [{
//1st breakpoint at 1024px
breakpoint: 1024,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: 3, slidesToScroll: 3
}
},{
//4th breakpoint at 767px
breakpoint: 767,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: 2, slidesToScroll: 2
}
},{
//4th breakpoint at 480px
breakpoint: 480,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: 1, slidesToScroll: 1
}
}]
});
});
}
/* AIG Caraousel Method - END */
/* Code to hide alert message --START */
$(document).ready(function () {
const $alertElement = $('div[class*="alert-"]');
// To check whether Alert component is exit or not
if($alertElement.length){
const currentElementID = $alertElement.find('.cmp-teaser').attr('id');
const alertElementID = getCookie('alertElementID');
/*To get alertMsg cookie*/
if(currentElementID === alertElementID) {
$alertElement.hide();
}
$alertElement.find('.cmp-teaser__action-link').on('click', function (e) {
e.preventDefault();
$alertElement.hide();
/*To set alertMsg cookie*/
const exdays = new Date();
exdays.setTime(exdays.getTime() + 90 * 24 * 60 * 60 * 1000);
document.cookie = 'alertElementID=' + currentElementID+'; expires=' + exdays;
return false;
});
}
});
/* Code to hide alert message --ENDS */
/* content toggle functionality */
$(document).ready(function() {
$('.teaser2023 .action-teaser-more a, .teaser2023 .action-teaser-less a').attr('href','javascript:;');
$('#less-content a[href*="more-content"], .teaser2023 .action-teaser-more').click(function(e) {
e.preventDefault();
const $contentDesc = $(this).closest('.cmp-teaser__description');
$contentDesc.find('.cmp-teaser__more-description').show();
$contentDesc.find('.action-teaser-less').show();
$contentDesc.find('.action-teaser-more').hide();
$('#less-content').hide();
$('#more-content').show();
});
$('#more-content a[href*="less-content"], .teaser2023 .action-teaser-less').click(function(e) {
e.preventDefault();
const $contentDesc = $(this).closest('.cmp-teaser__description');
$contentDesc.find('.cmp-teaser__more-description').hide();
$contentDesc.find('.action-teaser-more').show();
$contentDesc.find('.action-teaser-more a').focus();
$contentDesc.find('.action-teaser-less').hide();
$('#more-content').hide();
$('#less-content').show();
});
// Show more Text
$('.text2023 .action-more a').click(function(e) {
e.preventDefault();
const $contentDesc = $(this).closest('.cmp-text');
$contentDesc.find('.text-more').show();
$contentDesc.find('.action-less').show();
$contentDesc.find('.action-more').hide();
});
// Hide more text
$('.text2023 .action-less a').click(function(e) {
e.preventDefault();
const $contentDesc = $(this).closest('.cmp-text');
$contentDesc.find('.text-more').hide();
$contentDesc.find('.action-more').show();
$contentDesc.find('.action-less').hide();
});
});
/* content toggle functionality end*/
/* Start -> Show/hide quickLinks section (mobile view) */
$(function () {
$('.quick-links .title').click(function () {
$(this).parents('.quick-links').toggleClass('show');
});
});
/* End -> Show/hide quickLinks section (mobile view) */
/* quick link code start*/
$(function () {
//quick link href must start with #link-stick
$('a[href^="#link-stick"]').on('click', function (e) {
e.preventDefault();
const qLink = $(this).attr('href');
const qname = qLink.split('#');
const headerHeight = $('.aig-header.header-bar').height();
//getting header height
let emergencyBar = 0;
if ($('.emergencymessage').length) {
//for emergency header height
emergencyBar = $('.emergencymessage').height();
}
if($(window).width()>960){
$('html, body').animate({
scrollTop: $('#' + qname[1]).offset().top - (headerHeight + emergencyBar)
}, 'fast');
}
else{
$('html, body').animate({
scrollTop: $('#' + qname[1]).offset().top
}, 'fast');
}
});
});
/* quick link code end*/
/* For bread crumb code Starts Here for mobile and Deskptop*/
$(function() {
const links = $('.breadcrumb .cmp-breadcrumb__list li').length - 1;
$('.breadcrumb:not(.hide-ellipsis) .cmp-breadcrumb__list li').each(function(e) {
if (e > 1 && e !== (links - 1) && e !== links) {
$(this).addClass('desktop-hide'); // For Desktop Hide the Content
}
if (e === (links - 1) && links > 3) {
$(this).addClass('desktop-ellipsis'); // For Desktop add the ellipses(...)
}
if (e !== (links - 1) && e !== links && links > 0) {
$(this).addClass('mobile-hide'); // For Mobile hide the Content
}
if (e === (links - 1) && links > 0) {
$(this).addClass('mobile-ellipsis'); //For Mobile add the ellipses and arrow
}
});
/* For bread crumb code Ends Here for mobile and Deskptop*/
// To remove empty flex teaser under Hero banner with fade style
$('.hero-banner-with-fade > .cmp-container > .aem-Grid').each(function(){
const $this = $(this);
if($this.find('> .teaser').length){
if(!$this.find('> .teaser .cmp-teaser__image').length){
$this.find('> .teaser').remove();
$this.parent().addClass('no-hero');
}
}else{
$this.parent().addClass('no-hero');
}
});
});
/* For bread crumb code Ends Here for mobile and Deskptop*/
// Code to get Query param from Newsroom stories Starts
$(window).on('load', function () {
const articleTopicQueryParam = new URL(window.location.href);
const articleTopic = articleTopicQueryParam.searchParams.get('criteria');
if(articleTopic){
const filterDropdownOption = $('.filter .custom-select #filter-dropdown option');
filterDropdownOption.each(function(e){
// To check whether query param value is mathcing with Dropdown value or not
if($(this).val() === articleTopic){
$('.filter .custom-select #filter-dropdown').prop('selectedIndex', e).trigger('change');
$('.filter .custom-select .select-holder').html($(this).text());
$('.filter .custom-select .select-picker li').removeClass('select-active').removeAttr('aria-selected');
$('.filter .custom-select .select-picker li').eq(e).addClass('select-active').attr('aria-selected',true);
return;
}
});
}
});
// Code to get Query param from Newsroom stories End
$(document).ready(function () {
//code to add a placeholder to custom-select starts
$('.filter .custom-select .select-holder').html(' ').attr('data-placeholder','Select a filter');
$('.filter .custom-select #filter-dropdown').change(function(){
$(this).parents('.cmp-form-options').find('.select-holder').attr('data-placeholder','');
});
//code to add a placeholder to custom-select End
/*Code to show Multiple Dropdowns Starts*/
$('.aig-archive').each(function() {
const localOptTarget = $(this).find("[id^='multiple-option']");
$(this).find(localOptTarget).parent().hide();
$(this).find('select[name="multiple-dd"]').change(function () {
localOptTarget.parent().hide();
const selectedValuedd1 = $('#' + $(this).val());
if (selectedValuedd1.length) {
selectedValuedd1.parent().toggle();
}
});
});
/*Code to show Multiple Dropdowns Ends*/
/* Code to show default or selected archive year --START */
$('.aig-archive select[name="multiple-dd"]').each(function(){
const initialValue = $(this).val();
$('div#' + initialValue).parent().show();
});
$('.aig-archive .download .cmp-download__title-link').removeAttr('aria-hidden role');
/* Code to show default or selected archive year --Ends */
});
/* Aig Featured Job Js Starts */
$('.aig-featured-job').each(function() {
const $this = $(this);
const boldinfo = $this.find('.cmp-teaser__description b');
const authoreddate = $this.find('.cmp-teaser__description b').text();
let printfjyear;
let printfjmonth;
let printfjdays;
//Getting the values from datediff
const fjyear = dateDiff(authoreddate)['years'];
const fjmonth = dateDiff(authoreddate)['months'];
const fjdays = dateDiff(authoreddate)['days'];
//Comparing the year
if(fjyear===0){
printfjyear = '';
}
else if(fjyear===1){
printfjyear = fjyear + ' Year ';
}
else{
printfjyear = fjyear + ' Years ';
}
//comparing the month
if(fjmonth===0){
printfjmonth = '';
}
else if(fjmonth===1){
printfjmonth = fjmonth + ' Month ';
}
else{
printfjmonth = fjmonth + ' Months ';
}
//comparing the days
if(fjdays===0){
printfjdays = '';
}
else if(fjdays===1){
printfjdays = fjdays + ' Day';
}
else{
printfjdays = fjdays + ' Days';
}
//Comparing authored date and present date
if(fjyear===0 && fjmonth===0 && fjdays===0){
boldinfo.empty().text('Posted Today');
}
//Comparing authored date and present date
else if(fjyear===0 && fjmonth===0 && fjdays===1){
boldinfo.empty().text('Posted Yesterday');
}
//Comparing authored date and present date
else{
boldinfo.empty().text('Posted '+ printfjyear + printfjmonth + printfjdays +' Ago');
}
});
function dateDiff(date) {
date = date.split('-');
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1;
const day = today.getDate();
const yy = parseInt(date[2],10);
const mm = parseInt(date[0],10);
const dd = parseInt(date[1],10);
let years, months, days;
// To calculate difference of Months
months = month - mm;
if (day < dd) {
months = months - 1;
}
// To calculate difference of years
years = year - yy;
if (month * 100 + day < mm * 100 + dd) {
years = years - 1;
months = months + 12;
}
// To calculate difference of days
days = Math.floor((today.getTime() - (new Date(yy + years, mm + months - 1, dd)).getTime()) / (24 * 60 * 60 * 1000));
// To store the values in the array
return {years: years, months: months, days: days};
}
/* Aig Featured Job Js Ends */
/* tabbed cards script */
$(function() {
$('.tabbed-cards select').change(function(){
let tabpanel = $(this).val();
$('.tabbed-cards .tabs ol li').eq(tabpanel).trigger('click');
$(this).blur();
});
});
/* tabbed cards script ends*/
/* Aig Linkedin card Js Starts */
$('.aig-linkedin-card').each(function() {
const $this = $(this);
const boldinfo = $this.find('.cmp-teaser__pretitle');
const authoreddate = $this.find('.cmp-teaser__pretitle').text();
let printliyear;
let printlimonth;
let printlidays;
//Getting the values from datediff
const liyear = dateDiff(authoreddate)['years'];
const limonth = dateDiff(authoreddate)['months'];
const lidays = dateDiff(authoreddate)['days'];
//Comparing the year
if(liyear===0){
printliyear = '';
}
else if(liyear===1){
printliyear = liyear + ' year ';
}
else{
printliyear = liyear + ' years ';
}
//comparing the Months
if(limonth===0){
printlimonth = '';
}
else if(limonth===1){
printlimonth = limonth + ' month ';
}
else{
printlimonth = limonth + ' months ';
}
//comparing the days
if(lidays===0){
printlidays = '';
}
else if(lidays===1){
printlidays = lidays + ' day';
}
else{
printlidays = lidays + ' days';
}
//Comparing authored date and present date
if(liyear===0 && limonth===0 && lidays===0){
boldinfo.empty().text('today');
}
//Comparing authored date and present date
else if(liyear===0 && limonth===0 && lidays===1){
boldinfo.empty().text('yesterday');
}
//Comparing authored date and present date
else{
boldinfo.empty().text(printliyear + printlimonth + printlidays +' ago');
}
boldinfo.prependTo($this.find('.cmp-teaser__image'));
});
/* Aig Linkedin Card Js Ends */
/*filter,searchfilter js Starts*/
if($('.aig-article .searchfilter').length){
const searchfilter = $('.searchfilter');
const filteror = $("or ");
if($('.filter').length){
$('.filter .options').after(searchfilter);
$('.filter .options').after(filteror);
}
const searchfilterph = $('.cmp-searchfilter-article__keywordLabel').text();
$('.cmp-searchfilter-article__searchtext').attr('placeholder',searchfilterph);
searchfilter.find('.glyphicon-search').text('Search');
}
/*filter,searchfilter js Ends*/
/* Tab-layout Js starts */
$(document).ready(function () {
$('.aig-tab-layout.aig-carousel').on('breakpoint init click', function(){
addHover();
});
$('.aig-tab-layout.aig-carousel .cmp-tabs__tablist li').on('focus', function(){
addHover();
});
function addHover(){
$('.aig-tab-layout .cmp-tabs__tablist li.cmp-tabs__tab').each(function() {
//taking the url from data-imagepath adding to css
const src = 'url("'+ $(this).attr('data-imgpath')+'")';
$(this).css('background-image',src);
if($(this).hasClass('cmp-tabs__tab--active')){
//adding hover to end of the url
const hover = 'url("'+ $(this).attr('data-imgpath').replace('.png','-hover.png')+'")';
$(this).css('background-image',hover);
}
});
}
addHover();
// On click hover is added to the url
$('.aig-tab-layout .cmp-tabs__tablist li.cmp-tabs__tab').on('click',function() {
addHover();
});
/* Tab-layout Js ends */
/* thumbnail pannel JS starts */
$('.thumbnail-photo-gallery.aig-carousel').on('breakpoint', function(){
initThumbnailPhoto();
});
initThumbnailPhoto();
// Define Thumbnail Photo gallery method
function initThumbnailPhoto(){
$('.thumbnail-photo-gallery .cmp-tabs__tablist li.cmp-tabs__tab').each(function() {
//taking the url from data-imagepath adding to css
const src = 'url("'+ $(this).attr('data-imgpath')+'")';
$(this).css('background-image',src);
});
}
$('.thumbnail-photo-gallery .cmp-tabs__tablist li.cmp-tabs__tab').each(function(){
const txt=$(this).text();
$(this).attr('data-text',txt).text('');
});
// Thumbnail Photo Carousel for only in Mobile
$(window).on('load resize',function() {
if (window.matchMedia('(max-width:768px)').matches) {
$(window).resize(initThumbnailPhotoMobile);
}
});
function initThumbnailPhotoMobile(){
$('.thumbnail-photo-gallery.aig-carousel .tab-card-content').slick({
accessibility: true, arrows: true, dots: true, infinite: false, speed: 300, slidesToShow: 1, slidesToScroll: 1, mobileFirst: true,
responsive: [{ breakpoint: 767, settings: 'unslick'}]
});
}
/*thumbnail pannel JS Ends */
});
$(window).on('load resize',function() {
const headerVar = $('.aig-header.header-bar');
const secondarynavVar = $('.mobilesecondarynav');
const emergencyVar = $('.emergencymessage .emergency');
const emergencyMain = $('.emergencymessage');
const submenuIntro = $('.submenu-intro');
//To Check whether emergency message is empty or not
if(!emergencyMain.height()){
emergencyMain.addClass('hidden');
}
//if header is fixed and sticky
if(headerVar.length && headerVar.css('position') =='fixed'){
//if mobile-secondary-nav is present,add top margin to it
if(secondarynavVar.length && secondarynavVar.css('display') =='block'){
//add top margin
$('.mobilesecondarynav').css({'padding-top' : headerVar.height()});
$('main').css({'padding-top' : 0});
}
//if emergency message is present above header
//pageNavigated detected by emergency msg cookie
if(emergencyVar.length && emergencyVar.css('display') =='flex' ){
headerVar.css({'top' : $('.emergencymessage').height()});
submenuIntro.css({'top' : ($('.emergencymessage').height() + headerVar.height())});
if(secondarynavVar.length && secondarynavVar.css('display') =='block'){
//add top margin
$('.mobilesecondarynav').css({'padding-top' : headerVar.height() + $('.emergencymessage').height()});
$('main').css({'padding-top' : 0});
}
else{
$('main').css({'padding-top' : headerVar.height() + $('.emergencymessage').height()});
}
}
}
});
//if emergency message is clicked/closed
$('.emergencymessage .emergencyclose').click(function(){
const headerVar = $('.aig-header.header-bar');
const submenuIntro = $('.submenu-intro');
$('.emergencymessage').addClass('hidden');
//only if header is sticky
if(headerVar.length && headerVar.css('position') ==='fixed'){
//adjust top position of header
headerVar.css({'top' : 0});
submenuIntro.css({'top' : headerVar.height()});
if($('.mobilesecondarynav').length && $('.mobilesecondarynav').css('display') =='block'){
//add top margin
$('.mobilesecondarynav').css({'padding-top' : headerVar.height()});
//adjust top margin of main element
$('main').css({'padding-top' : 0});
}
else{
$('main').css({'padding-top' : headerVar.height()});
}
}
});
/* Back to Top button script Start*/
$(window).scroll(function () {
scrollTopNew();
});
function scrollTopNew(){
//fetching the top position of the footer
if($('.back_to_top').length){
let footertotop = ($('footer').position().top);
const goTop = ($('.back_to_top').position().top);
const stickyHeaderHeight = $('.aig-header.header-bar').height();
const stickyNavHeight = $('.sticky_nav').height();
const ESGstickyNavHeight = $('.sticky_navigation').height();
//check if there is pre-footer, and calculate top value
if($('.pre-footer').length){
footertotop = ($('.pre-footer').position().top);
}
const scrolltop = $(document).scrollTop() + window.innerHeight;
const difference = scrolltop-footertotop;
//remove back-to-top button overlap on header/stickynav
if( ( goTop < stickyHeaderHeight+20) || goTop < (stickyHeaderHeight+stickyNavHeight+20) ||
goTop < (stickyHeaderHeight+ESGstickyNavHeight+20)){
$('.back_to_top').hide();
}
//checking the position of the back to top button when text hides
let topTextwidth = $('.hide-BackToTop').width();
if (topTextwidth > 45) {
if (scrolltop >= footertotop) {
$('.back_to_top').css({'bottom' : difference + 20});
}else{
$('.back_to_top').css({'bottom' : 20});
}
}
//checking the position of the back to top button and positioning above the footer
if (topTextwidth < 45) {
if (scrolltop >= footertotop) {
$('.back_to_top').css({'bottom' : difference + 60});
}else{
$('.back_to_top').css({'bottom' : 60});
}
}
//code to check if messenger launcher is present
const messengerLauncher = $('.genesys-mxg-frame');
if($(messengerLauncher).length){
// getting height for messenger
const messengerLauncherheight = $(messengerLauncher).height();
const messengerLaunchertop = $(messengerLauncher).offset().top;
//button positioning
const newBottom = $(window).height()-(messengerLaunchertop - $(window).scrollTop()) + messengerLauncherheight;
if(newBottom >60){
$('.back_to_top').css('bottom' ,newBottom + 'px');
$('.back_to_top').css('right' ,'32px');
}
if (scrolltop >= footertotop) {
$('.back_to_top').css({'bottom' : difference + 130});
}
const mobileTablet=window.matchMedia("(max-width:1024px)").matches;
if(mobileTablet){
//to check if the device is android or ios
if(/ipad|iphone|ipod/.test(navigator.userAgent) || /android/i.test(navigator.userAgent)){
if($(messengerLauncher).length){
const messengerLauncherheight = $(messengerLauncher).height(); // getting height from messenger
const adjustedBottom = messengerLauncherheight + 80;
$('.back_to_top').css({'right':'32px' ,'bottom' : adjustedBottom + 'px'});
} else {
$('.back_to_top').css({'right' :'32px','bottom':'130px'}); //adjusting position of button
}
} else {
$('.back_to_top').css({'right' :'32px','bottom':'130px'});
}
if (scrolltop >= footertotop) {
$('.back_to_top').css({'bottom' : difference + 130});// back to top button should not exceed footer
}
}
}
}
}
/*code to hide the Back to top text */
$(document).ready(function () {
const buttonText = $('.back_to_top .cmp-button__text').text();
$('.back_to_top .cmp-button').each(function () {
$(this).attr("title", buttonText);
});
$('.back_to_top').after('' + buttonText + ' ');
let topTextwidth = $('.hide-BackToTop').width();
if (topTextwidth > 45) {
$('.back_to_top .cmp-button__text').hide();
}
});
/* Back to Top button script End*/
/* AIG Timeline carousel script */
$(function() {
$('.aig-timeline select').change(function(){
const tabpanel = $(this).val();
//hide the containers
$('.aig-timeline-carousel').parents('.aig-carousel').addClass('hideCarousel');
$('.aig-carousel .cmp-container#' + tabpanel).parent().removeClass('hideCarousel');
});
});
//containers show and hide
$(window).on('load',function() {
$('.aig-timeline-carousel').parents('.aig-timeline .aig-carousel').addClass('hideCarousel');
$('.aig-timeline-carousel').parents('.aig-timeline .aig-carousel:first-child').removeClass('hideCarousel');
});
/* AIG Timeline carousel script ends*/
/* Script to disable the add to calendar button if the event date crossed/passed today's date */
$(document).ready(function() {
const currentDate = new Date();
const day = currentDate.getDate();
const month = currentDate.getMonth();
const year = currentDate.getFullYear().toString();
const currentYear = parseInt(year.slice(year.length - 2),10);
const months = { 'Jan':0, 'Feb':1, 'Mar':2,'Apr':3,'May':4,'Jun':5,'Jul':6,'Aug':7,'Sep':8,'Oct':9,'Nov':10,'Dec':11};
$( '.upcoming-events .teaserflex' ).each(function(){
const dateString = $(this).find('.cmp-teaser__description').find('p:first').text().replace(/\u00a0/g, ' ');
if(dateString.length >= 9){
const eventDate = dateString.split(' ');
const eventYear = parseInt(eventDate[2],10);
const eventMonthStr = eventDate[1].split(',')[0];
const eventMonth = months[eventMonthStr];
const eventDay = parseInt(eventDate[0],10);
if(eventYear < currentYear || eventMonth < month || eventDay < day ){
$(this).find('.cmp-teaser__action-link').addClass('disabled-link');
}
if(eventYear === currentYear && eventMonth < month){
$(this).find('.cmp-teaser__action-link').addClass('disabled-link');
}
if(eventYear >= currentYear && eventMonth > month){
$(this).find('.cmp-teaser__action-link').removeClass('disabled-link');
}
}
});
});
// adding attributes to label and select
$(document).ready(function() {
setTimeout(function() {
$('.why-aig-container .options .cmp-form-option').each(function() {
$(this).find('.cmp-form-options label').attr('aria-label', 'label');
$(this).find('select').attr('aria-label', 'select');
});
}, 500);
});
// Ada issue fixes for tab card on multiple component.
$(function() {
$('.tab-card .cmp-tabs__tablist').attr('aria-busy','true');
});
// Ada issue fixes for tab card on multiple component ends here.
/* AIG Photopanel carousel script Starts */
$(window).on('load', function () {
const photoPanelUrl = window.location.pathname;
const photoPanel = photoPanelUrl.split('/');
//To get the last name from url
const photo = photoPanel[photoPanel.length - 1];
const photoName = photo.split('.')[0];
$('.image.aig-photo-panel .cmp-image').each(function() {
//getting id from panel
const panelStr= $(this).attr('id');
if(photoName === panelStr){
$(this).addClass('leadership-active');
const currentPhoto = '#'+panelStr;
// To set current position of Photo panal
$('.aig-carousel > .cmp-container > div').slick('slickGoTo',parseInt($('.aig-carousel .aig-photo-panel > div').index($(currentPhoto)), 10),false);
return;
}
});
});
/* AIG Photopanel carousel script Ends */
/* In accordion video component alignment script starts */
$(function() {
$('.accordion .cmp-accordion__panel .container .cmp-container .teaserflex ul').not('.accordion .cmp-accordion__panel .container .cmp-container .teaserflex p + ul').each(function(){
$(this).closest('.teaserflex').next('.videocomponent').css({'margin-left': '64px' , 'padding': '0px' , 'padding-right': '24px'});
$(this).closest('.teaserflex').next('.videocomponent').next('.teaserflex.teaser').css({'margin-left': '40px'});
$(this).closest('.teaserflex').next('.teaserflex.teaser').css({'margin-left': '40px'});
});
});
/* In accordion video component alignment script Ends */
$(function() {
$('#form-trigger label').each(function(e){
$(this).change(function(){
$('[id^="form-container"]').parent().removeClass('show').addClass('hide');
$('[id^="form-container"]').find('input, textarea').val(' ')
$('[id^="form-container-'+(e+1)+'"]').parent().addClass('show');
$('[id^="form-container-'+(e+1)+'"]').find('input, textarea').val('');
});
});
});
$(document).ready(function () {
$('.thumbnail-photo-gallery.aig-carousel .cmp-tabs ol.cmp-tabs__tablist, .aig-tab-layout.aig-carousel .cmp-tabs ol.cmp-tabs__tablist').find('div').removeAttr('aria-hidden tabindex');
$('.thumbnail-photo-gallery.aig-carousel .cmp-tabs ol.cmp-tabs__tablist').find('button').attr('role','tab');
});
$(document).ready(function () {
const accPdf = $('.accordion').find('.pdf-icon');
if(accPdf.length > 0){
accPdf.each(function(){
$(this).parents('.cmp-accordion__item').children('.cmp-accordion__header').find('.cmp-accordion__title').addClass('accordion_pdf_icon');
});
}
});
/*code to add a pdf icon for accordion Ends */
/* In Tabcard video component script starts */
if (window.matchMedia('(min-width:1440px)').matches) {
$(window).on('load resize',function() {
/* Script to fit video inside tabcard */
$(document).on('click', '.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .content__img-link', function() {
$(this).parents('.tabcard_video .cmp-container').css('margin','0');
$('#video-player').on('ended', function () {
$('.thumbnail-photo-gallery').find('.tabcard_video .cmp-container').css('justify-content','center');
});
});
$(document).on('click', '.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .video-popup .video-player-close', function() {
$(this).parents('.tabcard_video .cmp-container').css('justify-content','center');
});
if(('.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .video-popup.display--flex').length < 0) {
$(this).parents('.tabcard_video .cmp-container').css('justify-content','center');
}
/* Script to close video on click slide */
$('.thumbnail-photo-gallery').find('ol.cmp-tabs__tablist .slick-slide').on('click', function () {
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video-popup .video-player-close').trigger('click');
});
});
}
// video popup closes on click outside the videoplayer start
$('body').click(function (event){
if(event.target.id !=='img' && $(event.target).is('.video-popup')){
hideVideo();
removeTabcardStyle();
}
});
// video popup closes on click outside the videoplayer end
function removeTabcardStyle(){
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video').removeAttr('style');
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video__container.show-video-label .content__img-link img').removeAttr('style');
}
$(window).on('load resize',function() {
if (window.matchMedia('(min-width:768px)').matches) {
/* Script to fit video inside tabcard */
$(document).on('click', '.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .content__img-link', function() {
$(this).parents('.aig-video').attr('style', 'width: 100% !important; position: absolute');
$(this).parents('.aig-video').find('.videocomponent .video__container.show-video-label .content__img-link img').attr('style', 'display: none');
$(this).parents('.aig-video').find('.videocomponent .video-popup .video-player-close').show();
/* Script to close video on ended */
$('#video-player').on('ended', function () {
removeTabcardStyle();
});
/* Script to close video on Escape */
$(document).keydown(function(e) {
if (e.keyCode === 27 || e.which === 27) {
removeTabcardStyle();
}
});
});
$(document).on('click', '.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .video-popup .video-player-close', function() {
removeTabcardStyle();
$('.thumbnail-photo-gallery .aig-video #video-player').hide();
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
});
if(('.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .video-popup.display--flex').length < 0) {
removeTabcardStyle();
}
/* Script to close video on click slide */
$(document).on('click', '.thumbnail-photo-gallery ol.cmp-tabs__tablist .slick-slide', function() {
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video-popup .video-player-close').trigger('click');
});
setTimeout(function() {
/* Script to close video on click prev button */
$('.thumbnail-photo-gallery').find('ol .slick-prev.slick-arrow').on('click', function () {
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video-popup .video-player-close').trigger('click');
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
});
/* Script to close video on click next button */
$('.thumbnail-photo-gallery').find('ol .slick-next.slick-arrow').on('click', function () {
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video-popup .video-player-close').trigger('click');
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
});
}, 200);
}
});
/* script to enable video in mobile view for tab card*/
$(window).on('orientationchange', function() {
if (window.matchMedia('(min-width:753px)').matches) {
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video-popup .video-player-close').trigger('click');
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
}
});
$(window).on('load resize',function() {
if (window.matchMedia('(max-width:767px)').matches) {
removeTabcardStyle();
$('.thumbnail-photo-gallery').find('.aig-video').removeAttr('style');
$('.thumbnail-photo-gallery').find('.aig-video .videocomponent .video__container.show-video-label').removeAttr('style');
$(document).on('click', '.thumbnail-photo-gallery .tabcard_video .aig-video .videocomponent .content__img-link', function() {
removeTabcardStyle();
});
setTimeout(function() {
/* Script to close video on click prev button */
$('.thumbnail-photo-gallery').find('.tab-card-content .slick-prev.slick-arrow').on('click', function () {
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
});
/* Script to close video on click next button */
$('.thumbnail-photo-gallery').find('.tab-card-content .slick-next.slick-arrow').on('click', function () {
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
});
/* Script to close video on click slick dots */
$('.thumbnail-photo-gallery').find('.slick-dots li button').on('click', function () {
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').hide();
});
$('.thumbnail-photo-gallery').find('.tabcard_video .aig-video .videocomponent .video__container.show-video-label .content__img-link').on('click', function () {
$('.thumbnail-photo-gallery .aig-video .videocomponent .video-popup .video-player-close').show();
});
}, 200);
}
});
/* In Tabcard video component script ends */
// To create custome dropdown
function create_custom_dropdowns() {
$('.aig-dropdown-search select').each(function (i, select) {
if (!$(this).next().hasClass('dropdown-select')) {
$(this).after('');
const dropdown = $(this).next();
const options = $(select).find('option');
const selected = $(this).find('option:selected');
dropdown.find('.current').html(selected.data('display-text') || selected.text());
options.each(function (j, o) {
const display = $(o).data('display-text') || '';
dropdown.find('ul').append(' ' + $(o).text() + ' ');
});
}
});
$('.aig-dropdown-search .dropdown-select ul').each(function (i) {
$(this).before('
');
});
}
// Event listeners
// Open/close
$(document).on('click', '.aig-dropdown-search .dropdown-select', function (event) {
if ($(event.target).hasClass('dd-searchbox')) {
return;
}
// Toggle Dropdown
$('.aig-dropdown-search .dropdown-select').not($(this)).removeClass('open');
$(this).toggleClass('open');
if ($(this).hasClass('open')) {
$(this).find('.option').attr('tabindex', 0);
$(this).find('.selected').focus();
} else {
$(this).find('.option').removeAttr('tabindex');
$(this).focus();
}
});
// Close when clicking outside
$(document).on('click', function (event) {
if ($(event.target).closest('.aig-dropdown-search .dropdown-select').length === 0) {
$('.aig-dropdown-search.dropdown-select').removeClass('open');
$('.aig-dropdown-search.dropdown-select .option').removeAttr('tabindex');
}
event.stopPropagation();
});
// To filer drop down
function filterDropdown(i, e) {
const valThis = $('#txtSearchValue-' + i).val();
$(e).closest('.dropdown-select').find('ul > li').each(function () {
const text = $(this).text();
(text.toLowerCase().indexOf(valThis.toLowerCase()) > -1) ? $(this).show() : $(this).hide();
});
};
// Search
// Option click
$(document).on('click', '.aig-dropdown-search .dropdown-select .option', function (event) {
$(this).closest('.list').find('.selected').removeClass('selected');
$(this).addClass('selected');
const text = $(this).data('display-text') || $(this).text();
$(this).closest('.dropdown-select').find('.current').text(text);
$(this).closest('.dropdown-select').prev('select').val($(this).data('value')).trigger('change');
});
/* Keyboard events Start */
$(document).on('keydown', '.aig-dropdown-search .dropdown-select', function (event) {
const focused_option = $($(this).find('.list .option:focus')[0] || $(this).find('.list .option.selected')[0]);
// Space or Enter
//if (event.keyCode == 32 || event.keyCode == 13) {
if (event.keyCode === 13) {
if ($(this).hasClass('open')) {
focused_option.trigger('click');
} else {
$(this).trigger('click');
}
return false;
// Down
} else if (event.keyCode === 40) {
if (!$(this).hasClass('open')) {
$(this).trigger('click');
} else {
focused_option.next().focus();
}
return false;
// Up
} else if (event.keyCode === 38) {
if (!$(this).hasClass('open')) {
$(this).trigger('click');
} else {
const focused_option = $($(this).find('.list .option:focus')[0] || $(this).find('.list .option.selected')[0]);
focused_option.prev().focus();
}
return false;
// Esc
} else if (event.keyCode === 27) {
if ($(this).hasClass('open')) {
$(this).trigger('click');
}
return false;
}
});
/* Keyboard events End */
$(function () {
// To Init
create_custom_dropdowns();
$('.aig-dropdown-search .container').hide();
// bind change event to select
$('.aig-dropdown-search select').on('change', function () {
// get selected value
const optionValue = $(this).val();
if (optionValue) {
// To show alternate container
$('.aig-dropdown-search .container').hide();
$('.aig-dropdown-search .container .cmp-container').each(function () {
//show container with id that matches the option selected
if ($(this).attr('id') == optionValue) {
$(this).parent().show();
}
});
}
return false;
});
});
/*dropdown color change highlight start*/
setTimeout(
function setindividualclaimsPlaceholder() {
//setting the claims select first option value as the select holder data-placeholder attribute value
$('.aig-dropdown-search').each(function () {
const selectclaimsphvalue = $(this).find('.options select option:nth-child(1)').text();
//setting the casualty select first option value as the select holder data-placeholder attribute value
$(this).find('.options select').siblings('.dropdown-select').attr('data-placeholder', selectclaimsphvalue);
});
$('.aig-dropdown-search .options select').siblings('.dropdown-select').find('span').html(' ');
}, 500);
$(document).on('ready', function () {
setindividualclaimsPlaceholder();
});
$('.aig-dropdown-search select').on('change', function () {
$(this).siblings('.dropdown-select').attr('data-placeholder', '');
});
/*dropdown color change highlight end*/
$(function() {
$('.container.dynamic-media-container.aig-media').each(function() {
//get video descripion from attribute
const desc = $(this).find('.s7dm-dynamic-media').attr('data-description');
//get video duration from attribute
const duration = $(this).find('.s7dm-dynamic-media').attr('data-duration');
const time = parseInt((duration / 60),10) + ':' + ('0' + parseInt((duration % 60),10)).slice(-2);
// To check Dynamic video
if(duration === undefined || duration === null || duration === 0){
$(this).attr('data-time', '');
} else{
const time = parseInt((duration / 60),10) + ':' + ('0' + parseInt((duration % 60),10)).slice(-2);
$(this).attr('data-time', time);
}
$(' ').insertAfter($(this).find('.cmp-container')).html(desc);
$('clear ').insertBefore($(this).find('dialog .cmp-button .cmp-button__text'));
});
/*For video Duration Start */
$('.video__container').each(function() {
//get video duration from attribute
const duration = $(this).attr('data-duration');
if ($.isNumeric(duration) && duration !== 0) {
const time = parseInt((duration / 60), 10) + ':' + ('0' + parseInt((duration % 60), 10)).slice(-2);
$(this).attr('data-time', time);
} else {
$(this).attr('data-time', '');
}
});
/*For video Duration end */
/* Trigger multiple video Start */
$(document).on('click','[href*=video_trigger]', function(e){
e.preventDefault();
const target = '#'+$(this)[0].hash.substr(1);
$(target).find('.content__img-link').eq(0).trigger('click');
});
/* Trigger multiple video Start */
/*close button for dynamic media hero banner video start*/
$('.hero-banner-video').each(function() {
$('clear ').insertBefore($(this).find('dialog.container .cmp-button .cmp-button__text'));
});
/*close button for dynamic media hero banner video ends*/
/* Custom videocompoent focus set to vedio button on close of video popup start*/
$('.player--close').click(function () {
if($(this).closest('.hero-banner-video').length){
$(this).closest('.hero-banner-video').find('.cmp-teaser__action-link').focus();
}else {
$(this).closest('.videocomponent').find('.content__img-link').focus();
}
});
/* Custom videocompoent focus set to vedio button on close of video popup end*/
//Set the focus inside the video popup Start /*
$('.video-popup .player--close').on('keydown', function(e) {
const keyCode = e.keyCode;
if(keyCode === 9 ) {
e.preventDefault();
if(e.shiftKey){
setTimeout(function() {
$('.video-popup video').focus().select();
}, 1);
}
$(this).parent().find('video').focus();
}
});
$('.video-popup').on('keydown', function(e) {
if(e.keyCode === 9 && e.shiftKey) {
e.preventDefault();
$(this).parent().find('.player--close').focus();
}
});
//Set the focus inside the video popup End /*
});
// video popup closes on click outside the videoplayer start
$('body').click(function (event){
if(event.target.id !="img" && $(event.target).is('.video-popup')){
hideVideo();
}
});
// video popup closes on click outside the videoplayer end
// Hero background video spaces auto play start //
$(function() {
let videoId = $('.dynamic-hero-spaces .cmp-embed video');
// Remove control attribute
$(videoId).removeAttr('controls');
$(videoId).attr({
"loop": "",
"muted": "",
"playsinline": ""
});
$.each(videoId, function(){
this.muted = true;
this.loop = 'loop';
this.autoplay = 'autoplay';
this.play();
});
});
// Hero background video spaces auto play end //
/* Adjust the Hero Banner height based on the content */
function adjustHeroVideoHeight() {
const dynamicHeroSpace = '.dynamic-hero-spaces > .cmp-container > .aem-Grid';
$(dynamicHeroSpace).removeAttr('style');
$('.dynamic-hero-spaces .container:first').css({position: 'relative'});
const contentHeight = $('.dynamic-hero-spaces').find('.container').outerHeight();
let breadcrumbHeight = $('.dynamic-hero-spaces').find('.breadcrumb').outerHeight()
$(dynamicHeroSpace).css('min-height', contentHeight+breadcrumbHeight);
$('.dynamic-hero-spaces .container:first').css({position: 'absolute'});
}
$( document ).ready(function() {
const dynamicDesc = $('.dynamic-hero-spaces.transparent.annimate_content .teaser .cmp-teaser .cmp-teaser__content .cmp-teaser__description');
// add annimate class to description if there is no image in description //
if(dynamicDesc.find("p").length == 1){
dynamicDesc.addClass('annimate');
}
// On page load adjust the image height
setTimeout(function() {
adjustHeroVideoHeight();
dynamicDesc.css('visibility','visible');
$('.dynamic-hero-spaces').addClass('start');
}, 500);
let resizeTimer;
$(window).on('resize',function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
adjustHeroVideoHeight();
}, 800);
});
});
$(document).ready(function() {
setTimeout(function() {
$('.dynamicmedia .cq-dd-image .s7dm-dynamic-media .s7container .s7socialshare .s7button').attr('tabindex','-1');
$('.dynamicmedia .cq-dd-image .s7dm-dynamic-media .s7container .s7controlbar .s7button').attr('tabindex','-1');
$('.dynamicmedia .cq-dd-image .s7dm-dynamic-media .s7container .s7controlbar .s7videoscrubber .s7knob').attr('tabindex','-1');
}, 2400);
});
/* Script to hide newsroom form--start */
$(document).on('click', '[aria-label=popup-close]', function () {
$(this).parents('dialog.container').removeClass('popup-dialog');
$(this).parents('dialog.container').attr({ 'aria-expanded': 'false' });
$('.open-popup').focus().attr({ 'aria-expanded': 'false', tabindex: '0' }).removeClass('open-popup');
});
/* Script to hide newsroom form--end */
/*******************************************************************************
*
*
* Copyright 2016 Adobe
*
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
******************************************************************************/
/* Script for Search Field in Header and search-results page -- START */
$(function () {
//hide no-results text if thre is no search term
if ($('.search2023 form input[name=q]').val() === '') {
$('.no-search-results').hide();
}
//show clear icon
clearInput();
/*
*search is made from HEADER
*/
//hide hidden field
$('input#header-search-path').parent().hide();
//add EMPTY quick-lists div to header search field
$(".header-search form input[name=searchkey]")
.parent()
.append(
''
);
$('.header-search form input[name=searchkey]').closest('.text').attr('role','search');
let checkSpecailChar = true;
let blacklistChars, errorMsg, doubleQouteCheck,blacklistCharsArray;
// check for special char configured in lang node
if($("meta[blacklistedSpecialChars]").length){
blacklistChars = $("meta[blacklistedSpecialChars]").attr("blacklistedSpecialChars");
errorMsg = $("meta[blacklistedSpecialChars]").attr("searchErrorMessage");
doubleQouteCheck = $("meta[blacklistedSpecialChars]").attr("doubleInvertedCommaBlacklisted");
blacklistCharsArray = blacklistChars.split("-");
if(doubleQouteCheck){
blacklistCharsArray.push('"');
}
}
$('body').on('input','.header-search form input[name=searchkey]', function () {
//if search is made from HEADER , set location to 1.
const inputLocation = 1;
const userInput = $('.header-search form input[name=searchkey]').val();
// if block listed special chars are added in the language node, then block the user to enter
if($("meta[blacklistedSpecialChars]").length){
checkSpecailChar = true;
//check if any special char is entered in the search input
for(var i=0;i= 0)){
checkSpecailChar = false;
// append the error message configured in language node
$('.header-search .quick-results').append(''+errorMsg+' ');
$('.header-search .quick-lists').css('display','block');
$('.header-search form').find('.cmp-form-button').prop('disabled', true);
return;
}else{
$('.header-search form').find('.cmp-form-button').prop('disabled', false);
}
}
}
//initially empty search suggestions and show page scroll bar
$('.quick-results').html('');
$('html').css('overflow','auto');
//show suggestions on input of 3 more characters
if (userInput.length >= 3 && checkSpecailChar) {
//fetch suggestions
fetchSuggestions(userInput, inputLocation);
}
}
);
/*
*search is made from ADVANCE SEARCH component
*/
$('.search2023 form input[name=q]').on('keyup', function (e) {
//if search is made from ADVANCE SEARCH component, set location to 2.
const inputLocation = 2;
const userInput = $('.searchbar').val();
// if block listed special chars are added in the language node, then block the user to enter
if($("meta[blacklistedSpecialChars]").length){
checkSpecailChar = true;
//check if any special char is entered in the search input
for(var i=0;i= 0)){
checkSpecailChar = false;
// append the error message configured in language node
$('.search2023 .quick-results').append(''+errorMsg+' ');
$('.search2023 .quick-lists').css('display','block');
$('.search2023 form').find('.search-results-search-icon').prop('disabled', true);
return;
}else{
$('.search2023 form form').find('.search-results-search-icon').prop('disabled', false);
}
}
}
//initially empty search suggestions and show page scroll bar
$('.quick-results').html('');
$('html').css('overflow','auto');
//check for valid input
clearInput();
const currNode = window.location.origin + window.location.pathname + '?q=' + encodeURIComponent($('.searchbar').val());
$('.clearall .cmp-button').attr('href', currNode);
//show suggestions on input of 3 more characters
if (userInput.length >= 3 && $('.search-field--wrapper').length) {
//fetch suggestions
fetchSuggestions(userInput, inputLocation);
}
//if enter is pressed in search field
if(e.which === 13){
e.preventDefault();
window.location.replace(sanitizeText(currNode));
}
});
/* on click of dd execute the below code*/
$('.search-field').on('click','.quick-lists .quick-suggestions dd',function () {
const $form = $(this).closest('form');
const $searchField = $form.find('input[name=q]');
const autoComplete = $(this).text();
$searchField.val(autoComplete);
/* form submit */
$form.submit();
});
});
/* function to sanitize JSON response */
function sanitizeJSON(a) {
return a.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/\f/g, '\\f');
}
/* function to decode response */
function decodeResponse(a) {
return decodeURIComponent(a.replace(/\+/g, '%20'));
}
/* function to fetch auto complete suggestions */
function fetchSuggestions(userInput, inputLocation) {
let currNode = '';
let currPage = '';
//current node
if (inputLocation === 1) {
currNode = $('input#header-search-path').val();
currPage = window.location.protocol + '//' + window.location.host + currNode.split('.html')[0];
}
if (inputLocation === 2) {
currNode = $('#search-results-page').attr('data-currnode');
currPage = window.location.protocol + '//' + window.location.host + $('#search-results-page').attr('data-currnode').split('.html')[0];
}
//target url for req
const targetUrl = currPage + '/quick-results.results.json?q=' + '' + '&QRParam=' + encodeURIComponent(userInput);
//request to get search data
$.ajax({
type: 'GET',
url: targetUrl,
dataType: 'html',
beforeSend: function () {
$('.quick-results').html('');
//code to show loading icon
},
complete: function () {
//make input location to EMPTY on req. completion
inputLocation = '';
//code to hide loading icon
},
success: function (response) {
//sanitizing response
const a = sanitizeText(response);
const responseData = JSON.parse(a);
const returnedData = JSON.parse(sanitizeJSON(JSON.stringify(responseData)));
//primary language set at current country node
const primLang = returnedData.currentCountryPrimaryLanguage;
const x = currNode.split('/', 5).join('/').length;
const y = currNode.split('/', 6).join('/').length;
const currLang = currNode.substring(x, y + 1).replaceAll('/','');
//checking path for for each resulting item
$.each(returnedData.results, function (index, result) {
//resultant path decoded
const resPath = decodeResponse(result.path);
let before = '';
const fifthSlash = resPath.split('/', 5).join('/').length;
const sixthSlash = resPath.split('/', 6).join('/').length;
const langNode = resPath.substring(fifthSlash, sixthSlash + 1);
//if path has language node
if (resPath.includes('/content/') && resPath.includes(langNode)) {
//get path after lang node
const pathArr = resPath.split(langNode)[1].split('.')[0].split('/');
//avoid the last/current node string
pathArr.splice(-1);
//if no nodes in the path, make breadcrumb empty
if(pathArr.length === 0){before = '';}
//if more than 3 nodes in the path, separate with '>...>'
else if (pathArr.length > 2) {
before = pathArr[0] + ' > ... > ' + pathArr[pathArr.length - 1];
}
//if 3 or less nodes in the path, separate with '>'
else {before = pathArr.join(' > ');}
} else {
let pathArr = resPath.replaceAll('/', '>').split('>');
//remove 0th empty item from the array
const resPathArr = pathArr.filter((data,id)=>id !== 0);
//to check if the path contains primary language, returns -1 if not present
const i = resPathArr.indexOf(returnedData.currentCountryPrimaryLanguage);
//avoid the last/current node string
resPathArr.splice(-1);
//if the breadcrumb does not contain primary lang string,remove first string
if (i<0 && currLang!==primLang) {
resPathArr.splice(0,1);
}
//if no nodes in the path, make breadcrumb empty
if(resPathArr.length === 0){before = '';}
//if more than 3 nodes in the path, separate with '>...>'
else if (resPathArr.length > 2) {
before = resPathArr[0] + ' > ... > ' + resPathArr[resPathArr.length - 1];
}
//if 3 or less nodes in the path, separate with '>'
else {before = resPathArr.join(' > ');}
}
const breadcrumb = '' + before + '
';
//request made from HEADER, show suggestions below HEADER
if (inputLocation === 1) {
$('.header-search .quick-results').append('' + decodeResponse(result.title) + ' ' + breadcrumb + ' ');
}
//request made from ADVANCED SEARCH, show suggestions below ADVANCED SEARCH
if (inputLocation === 2) {
$('.search2023 .quick-results').append('' + decodeResponse(result.title) + ' ' + breadcrumb + ' ');
$('.search2023').css('min-height', $('.search-field--wrapper').height() + 40);
}
//display search suggestions and hide page scroll
$('.quick-lists').css('display', 'block');
$('html').css('overflow', 'hidden');
});
}
});
}
/* function to clear search input field */
$(document).on('click', '.search-field-clear', function (e) {
e.preventDefault();
$('.searchbar').val('');
$('.search-field-clear').remove();
});
/* function to hide search suggestions on focus out */
$(document).on('keydown', function (e) {
const keyCode = e.keyCode;
//if focus is on last item and tab key is pressed
if(keyCode === 9 && e.target.matches('.quick-lists .quick-results__item:last-child a')){
if(e.shiftKey){
//goto previous item (default behavior) if SHIFT + TAB key is pressed
return;
} else{
//hide quick list suggestions if only TAB key is pressed after last item
$('.quick-lists').css('display','none');
$('html').css('overflow', 'auto');
}
}
});
$(document).on('click', function (e) {
// Hide the advanced search suggestions and enable page scroll,
// if the user clicks anywhere outside of it
if (!e.target.matches('.quick-lists')) {
$('.quick-lists').css('display','none');
$('html').css('overflow', 'auto');
}
});
/* function to add clear icon */
function clearInput(){
const searchClear = ' ';
if (!$('.search-results-search-box').find('.search-field-clear').length) {
$('.search-results-search-box').append(searchClear);
}
if (!$('.searchbar').val()) {
$('.search-field-clear').remove();
}
}
/* Script for Search Field in Header and search-results page -- END */
/* search focus in mobile mode start*/
$('.searchbar').each(function() {
$(window).on('load', function() {
if ($(window).width() < 960) {
setTimeout(function(){
$('.searchbar').focus();
$(window).scrollTop(0);
},200);
}
});
});
/* search focus in mobile mode end*/
/*search input field width updated dynamically start*/
$(window).on('load resize', function () {
if($('.aig-header').length){
//to calculate logo and rightnav width
const logoWidth = $('.aig-header .aig-logo img').width();
const rightnavWidth = $('.aig-header .header-search + .right-nav-container').width();
//to calculate total width
let totalWidth = logoWidth + rightnavWidth;
if($(window).width()>1200){
$('.aig-header .header-search').css({ 'width': 'calc(83.3333% - ' + totalWidth+ 'px)', 'right': 'calc(8.33% + ' + rightnavWidth+ 'px)'});
}
else{
//it applies when window width is less than or equal to 1200
$('.aig-header .header-search').css({ 'width': 'calc(100% - (' + totalWidth+ 'px + 64px))', 'right': 'calc(32px + ' + rightnavWidth+ 'px)'});
}
}
});
/*search input field width updated dynamically end*/
$(function() {
let dataArray;
//Primary & Secondary select box selectors
const primarySelect = 'select.cmp-form-options__field--drop-down[name="claim-type"]';
const secondarySelect = 'select.cmp-form-options__field--drop-down[name="casualty-type"]';
//get JSON URL from hidden field
const jsonPath = $('input[name="claims-url"]').val();
//Initial Ajax call to fetch data
if ($(primarySelect).length && $(secondarySelect).length) {
$.ajax({
url: jsonPath,
type: 'GET',
contentType: 'application/json; charset=utf-8',
dataType: 'json'
}).done(function(data) {
const sanitizedData = JSON.parse(sanitizeJSON(JSON.stringify(data)));
dataArray = sanitizedData.properties.elements.products.value;
setClaimType(dataArray, primarySelect);
});
//Add outer class to the container
$(primarySelect).parents('.container').addClass('aig-report-claim');
$(secondarySelect).prev('label').hide();
$(secondarySelect).next('.select-holder').hide();
}
//Override the default functionality on clicking first list item containing input field
$('body').on('click', '.aig-report-claim ul.select-picker li:first-child', function() {
return false;
});
//Search functionality for input field within dropdown
$('body').on('keyup', '.aig-report-claim ul.select-picker div.filterList .filterText', function() {
//Find search term
const searchText = $(this).val();
$(this).parents('fieldset').find('ul.select-picker li').each(function() {
const claimtype = ($(this).attr('data-heading') + '').toLowerCase();
const headingItem = '#list' + $(this).attr('data-index');
if ($(this).text().toLowerCase().indexOf(searchText.toLowerCase()) === -1 && $(this).text() !== '' && claimtype !== searchText) {
//hide items if search term is absent
$(this).hide();
} else {
//show items if search item is present
$(this).show();
if ($(this).attr('data-index')) {
$(headingItem).show();
}
}
});
});
//On change function for dropdown to display the cards
$(primarySelect).change(function() {
const claimType = $(this).val();
$(this).siblings('.select-holder').attr('data-placeholder','');
//storing data-heading value of casualty-type in subCategory variable
const subCategory = $(this).find('option:selected').attr('data-heading');
$('.aig-report-claim .text.aig-claims-content').html('');
//to show the card if they select any sub-category
if(subCategory){
getCard(subCategory, claimType, true, dataArray);
$(secondarySelect).next('.select-holder').hide();
}
else{
//set secondary dropdown values
setCasualtyType(claimType, dataArray, secondarySelect);
$(secondarySelect).next('.select-holder').show();
//code to empty the select value and add data-placeholder attribute
$('.aig-report-claim .custom-select select[name="casualty-type"]').siblings('.select-holder').html(' ');
const selectcasualtyphvalue = $('.aig-report-claim .custom-select select[name="casualty-type"] option:nth-child(1)').text();
$('.aig-report-claim .custom-select select[name="casualty-type"]').siblings('.select-holder').html(' ').attr('data-placeholder',selectcasualtyphvalue);
}
});
$(secondarySelect).change(function() {
const casualtyType = $(this).val();
$(this).siblings('.select-holder').attr('data-placeholder','');
const claimType = $(primarySelect).val();
if (claimType && casualtyType) {
//when secondary and primary options are present
getCard(claimType, casualtyType, true, dataArray);
}
});
});
//Function to Sanitize JSON data
function sanitizeJSON(a) {
return a.replace(/\n/g, '\\n').replace(/'/g, "\\'").replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/\f/g, '\\f').replace(/\&/g, '\\&');
}
//Populate Dropdown
function populateList(primary,secondary,dropdown) {
let options = '';
let listItems = '';
for (const i in primary) {
if (primary[i] !== '' && secondary !== '' ) {
options += ` ${primary[i]} `;
listItems += `${primary[i]} `;
if(secondary.length){
for (const j in secondary) {
if (primary[i] === secondary[j][0] && secondary[j][1] !== '') {
//Populate casualty items in claims drop-down
options += `${secondary[j][1]} `;
listItems += `${secondary[j][1]} `;
}
}
}
}
else{
//seconday dropdown creation
options += ` ${primary[i]} `;
listItems += `${primary[i]} `;
}
}
$(dropdown).parents('fieldset').find('ul.select-picker li:first-child').text('').append('
');
$(dropdown).parents('fieldset').find('ul.select-picker').append(sanitizeText(listItems));
$(dropdown + ' option:gt(0)').remove();
$(dropdown).append(sanitizeText(options));
/* Adding ID's to sub heading dynamically STARTS */
let sh_value = 0;
$('.select-picker li[data-index]').each(function(){
$(this).attr('id','SH'+sh_value);
sh_value++;
});
/* Adding ID's to sub heading dynamically ENDS */
}
//Determine primary category/secondary category arrays based on fetched data
function setClaimType(dataArray, primarySelect) {
const options = [];
const primary = [];
const secondary = [];
for (const i in dataArray) {
if ((JSON.parse(dataArray[i])).primarycategory !== '') {
primary.push((JSON.parse(dataArray[i])).primarycategory);
}
}
//Find unique values in array
const unique = [...new Set(primary.map(item => item))];
for (const j in unique) {
options[j] = unique[j];
}
//Creating secondary array
for (let k = 0; k < options.length; k++) {
for (const l in dataArray) {
if ((JSON.parse(dataArray[l])).primarycategory === options[k]) {
secondary.push([(JSON.parse(dataArray[l])).primarycategory, (JSON.parse(dataArray[l])).secondarycategory]);
}
}
}
populateList(options,secondary,primarySelect);
}
//Populate Casualty dropdown dynamically based on Claim type dropdown
function setCasualtyType(claim, dataArray, secondarySelect) {
//reset secondary dropdown
const firstOption = $(secondarySelect + ' option:first-child').text();
$(secondarySelect).val('0').parents('fieldset').find('.select-holder').text(firstOption);
$(secondarySelect).parents('fieldset').find('.select-picker li:gt(0)').remove();
const options = [];
for (const i in dataArray) {
//Parse json to find matching secondary items
if ((JSON.parse(dataArray[i])).primarycategory === claim) {
options.push((JSON.parse(dataArray[i])).secondarycategory);
}
}
populateList(options,'',secondarySelect);
//When secondary options are absent
if (options.length<=1) {
getCard(claim, '', false, dataArray);
$(secondarySelect).parents('fieldset').hide();
} else {
$(secondarySelect).parents('fieldset').show();
}
}
//Display Card from external HTML page
function getCard(claimType, casualtyType, params, dataArray) {
let path;
for (const i in dataArray) {
if (params) {
if ((JSON.parse(dataArray[i])).primarycategory === claimType && (JSON.parse(dataArray[i])).secondarycategory === casualtyType) {
if((JSON.parse(dataArray[i])).path !== ''){
path = `${(JSON.parse(dataArray[i])).path}.html`;
}
}
} else {
if ((JSON.parse(dataArray[i])).primarycategory === claimType) {
if((JSON.parse(dataArray[i])).path !== ''){
path = `${(JSON.parse(dataArray[i])).path}.html`;
}
}
}
}
// set card heading - with/without secondary option
let cardHeading = claimType + ' - ' + casualtyType;
if (!casualtyType) {
cardHeading = claimType;
}
//Ajax call to fetch card data from external page
$.ajax({
url: path,
type: 'GET',
dataType: 'html'
}).done(function(data) {
$('.aig-report-claim div:not(.aig-dropdown-search) .text.aig-claims-content').html(`${cardHeading} ${sanitizeText(data)}
`);
});
}
setTimeout(
function setclaimsPlaceholder(){
//setting the claims select first option value as the select holder data-placeholder attribute value
const selectclaimsphvalue = $('.aig-report-claim .custom-select select[name="claim-type"] option:nth-child(1)').text();
//setting the casualty select first option value as the select holder data-placeholder attribute value
const selectcasualtyphvalue = $('.aig-report-claim .custom-select select[name="casualty-type"] option:nth-child(1)').text();
$('.aig-report-claim .custom-select select[name="claim-type"]').siblings('.select-holder').html(' ').attr('data-placeholder',selectclaimsphvalue);
$('.aig-report-claim .custom-select select[name="casualty-type"]').siblings('.select-holder').html(' ').attr('data-placeholder',selectcasualtyphvalue);
},500);
$(document).on('ready',function() {
setclaimsPlaceholder();
});
/* Updating aria-activedescendant value according to current element STARTS */
$(document).ready(function() {
let sctop =0;
/* Onclick down arrow updating the value Starts*/
$('.options.custom-select .select-holder').on('keydown', function (e) {
let keyCode = e.keyCode;
const x= $(this);
listscroll(x,keyCode);
});
$('.options.custom-select ul.select-picker li').on('keydown', function (e) {
let keyCode = e.keyCode;
const x= $(this).parents('.options.custom-select').find('.select-holder');
listscroll(x,keyCode);
});
function listscroll(x,keyCode) {
let isScrollTop = false;
let $selectOuterHeight = x.siblings().find('.select-active').outerHeight();
const $selectPicker = x.next('.select-picker');
let $selectListLength = $selectPicker.find('li').length;
let scbottom = $selectListLength * $selectOuterHeight;
const $selectedListItemLast = $selectPicker.find('li:last');
const selectActive = 'select-active';
const $selectedListItemFirst = $selectPicker.find('li:first');
if(keyCode === 13){
sctop=0;
}
if(keyCode === 40){
if(!isScrollTop){
$(window).scrollTop(x.offset().top-140);
isScrollTop = true;
}
let id_value =x.siblings().find('.select-active').next().attr('id');
$('.options.custom-select .cmp-form-option').each(function() {
x.find('.cmp-form-options >.select-holder').attr('aria-activedescendant',id_value);
});
/* Onclick down arrow updating the top value Starts*/
x.next().scrollTop(sctop);
sctop = sctop + $selectOuterHeight;
if ($selectedListItemLast.hasClass(selectActive)) {
sctop =0;
x.next().scrollTop(sctop);
}
/* Onclick down arrow updating the top value Ends*/
}
/* Onclick up arrow updating the top value Starts*/
if(keyCode === 38){
if(!isScrollTop){
$(window).scrollTop(x.offset().top-140);
isScrollTop = true;
}
sctop = sctop - $selectOuterHeight;
x.next().scrollTop(sctop);
if ($selectedListItemFirst.hasClass(selectActive)) {
sctop = scbottom - (3*$selectOuterHeight);
x.next().scrollTop(sctop);
}
if ($selectedListItemLast.hasClass(selectActive)) {
sctop = scbottom - (3*$selectOuterHeight);
console.log(sctop);
x.next().scrollTop(sctop);
}
}
/* Onclick up arrow updating the top value Ends*/
}
/* Onclick down arrow updating the value Ends*/
/* Onclick up arrow updating the value Starts*/
$('.options.custom-select .select-holder').on('keydown', function (e) {
let keyCode = e.keyCode;
if(keyCode === 38){
let id_value =$(this).siblings().find('.select-active').prev().attr('id');
$('.options.custom-select .cmp-form-option').each(function() {
$(this).find('.cmp-form-options >.select-holder').attr('aria-activedescendant',id_value);
});
}
});
/* Onclick up arrow updating the value Ends*/
});
/* Updating aria-activedescendant value according to current element ENDS */
/* To update placeholder text Starts */
$(document).ready(function() {
const inhid = $('.aig-dropdown-search >.cmp-container >.aem-Grid >.hidden input[name="claim-placeholder-text"]');
if(inhid.length){
const individualph = inhid.attr('value');
$('.aig-dropdown-search').find('.dropdown-select .list .dd-search .dd-searchbox').attr('placeholder',individualph);
}
businessphReplace();
});
//function to business placeholder
function businessphReplace(){
const bshid = $('.aig-report-claim >.cmp-container >.aem-Grid >.hidden input[name="claim-placeholder-text"]');
if(bshid.length){
let businessph = bshid.attr('value');
setTimeout(function() {
$('.aig-report-claim').find('.options.custom-select ul.select-picker li div.filterList input.filterText').attr('placeholder',businessph);
},1000);
}
}
//on click list calling business placeholder function
$('body').on('click', '.aig-report-claim ul.select-picker li', function() {
businessphReplace();
});
/* To update placeholder text Ends */
let enterPaths = [];
$(function() {
let dataArray;
const dropdown = 'select.cmp-form-options__field--drop-down[name="why-aig"]';
const jsonURL = $('input[name="why-aig-url"]').val();
if ($(dropdown).length) {
//Initial Ajax call to fetch data
$.ajax({
url: jsonURL,
type: 'GET',
contentType: 'application/json; charset=utf-8',
dataType: 'json'
}).done(function(data) {
const sanitizedData = JSON.parse(sanitizeJSON(JSON.stringify(data)));
dataArray = sanitizedData.properties.elements.products.value;
createArray(dataArray, dropdown);
});
$(dropdown).parents('.container').addClass('why-aig-container');
}
//function to sanitize JSON data
function sanitizeJSON(a) {
return a.replace(/\n/g, '\\n').replace(/'/g, "\\'").replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/\f/g, '\\f').replace(/\&/g, '\\&');
}
//Override the default functionality on clicking first list item containing input field
$('body').on('click', '.why-aig-container ul.select-picker li:first-child', function() {
return false;
});
//Search functionality for input field within dropdown
$('body').on('keyup', '.why-aig-container ul.select-picker div.filterList .filterText', function(e) {
const searchText = $('.filterList .filterText').val().toLowerCase();
const enterPrimary = [];
const enterSecondary = [];
$(dropdown).parents('fieldset').find('ul.select-picker li').each(function() {
const mainCategory = ($(this).attr('data-heading') + '').toLowerCase();
const subCategory = $(this).text().toLowerCase();
const headingItem = '#list' + $(this).attr('data-index');
if (subCategory.indexOf(searchText) !== -1 || subCategory === '' || mainCategory === searchText) {
if ($(this).attr('data-index')) {
$(headingItem).show();
}
//Enter Functionality
if(e.keyCode===13 && $(this).text()!==''){
enterPaths = [];
$('.text.aig-claims-content').html('');
if(!$(this).attr('data-heading')){
//pushing primary category to enterPrimary variable
enterPrimary.push($(this).text());
}
else{
//pushing secondary category to enterSecondary variable
enterSecondary.push([$(this).attr('data-heading'),$(this).text()]);
for(let p=0;p${sanitizeText(data)}`;
$(cards).appendTo('.text.aig-claims-content');
});
}
}
}
enterFunctionality();
});
//On change function for dropdown to display the cards
$(dropdown).change(function() {
$(this).siblings('.select-holder').attr('data-placeholder','');
$('.aig-solution-card').hide();
const secondaryType = $(this).find('option:selected').text();
const primaryType = $(this).find('option:selected').attr('data-heading');
//if both main & subcategories are present
if (primaryType && secondaryType) {
getSingleCard(primaryType, secondaryType, true, dataArray, 0);
}
//When category is selected multiple cards are shown
if (!primaryType && $(this).find('option:selected').next('option').attr('data-heading') === secondaryType) {
getMultipleCards(secondaryType, dataArray, dropdown, 0);
}
//secondary category is absent
if (!primaryType && $(this).find('option:selected').next('option').attr('data-heading') !== secondaryType) {
getSingleCard(primaryType, secondaryType, false, dataArray, 0);
}
});
});
//Determine primary category/secondary category arrays based on fetched data
function createArray(dataArray, dropdown) {
const options = [];
const primary = [];
const secondary = [];
//Create primary array
for (const i in dataArray) {
if (dataArray[i]) {
primary.push((JSON.parse(dataArray[i])).primarycategory);
}
}
//Finding unique items in the array
const unique = [...new Set(primary.map(item => item))];
for (const j in unique) {
options[j] = unique[j];
}
//Creating secondary array
for (let k = 0; k < options.length; k++) {
for (const l in dataArray) {
if ((JSON.parse(dataArray[l])).primarycategory === options[k]) {
secondary.push([(JSON.parse(dataArray[l])).primarycategory, (JSON.parse(dataArray[l])).secondarycategory]);
}
}
}
populateDropdown(options, secondary, dropdown);
}
//Populate Dropdown & List element using primary & secondary arrays
function populateDropdown(primary, secondary, dropdown) {
let options = '';
let listItems = '';
for (let i = 0; i < primary.length; i++) {
//Populate primary category items
options += `${primary[i]} `;
listItems += `${primary[i]} `;
for (const j in secondary) {
if (primary[i] === secondary[j][0] && secondary[j][1] !== '') {
//Populate secondary category items
options += `${secondary[j][1]} `;
listItems += `${secondary[j][1]} `;
}
}
}
//Dynamically append search field
$(dropdown).parents('fieldset').find('ul.select-picker li:first-child').text('').append('
');
$(dropdown).parents('fieldset').find('ul.select-picker').append(sanitizeText(listItems));
$(sanitizeText(options)).appendTo(dropdown);
/* Adding ID's to sub heading dynamically STARTS */
let sh_value = 0;
$('.select-picker li[data-index]').each(function(){
$(this).attr('id','SH'+sh_value);
sh_value++;
});
/* Adding ID's to sub heading dynamically ENDS */
}
//Display Single Card from external HTML page
function getSingleCard(primaryType, secondaryType, params, dataArray,pathValue) {
let path;
for (const i in dataArray) {
if (params) {
//When primary & secondary categories are available
if ((JSON.parse(dataArray[i])).primarycategory === primaryType && (JSON.parse(dataArray[i])).secondarycategory === secondaryType) {
path = `${(JSON.parse(dataArray[i])).path}.html`;
}
} else {
//When primary category alone is available
if ((JSON.parse(dataArray[i])).primarycategory === secondaryType) {
path = `${(JSON.parse(dataArray[i])).path}.html`;
}
}
}
if(pathValue===0){
//Ajax call to fetch data from external page
$.ajax({
url: path,
type: 'GET',
dataType: 'html'
}).done(function(data) {
$('.text.aig-claims-content').html(` ${sanitizeText(data)}
`);
});
}
//if pathvalue 1 means to store data only on enter functionality
if(pathValue===1){
enterPaths.push(path);
}
}
//Display Multiple Cards from external HTML page
function getMultipleCards(primaryType, dataArray, dropdown,pathValue) {
const secondaryTypes = [];
//Find sub categories based on main category
$(`${dropdown} option[data-heading="${primaryType}"]`).each(function() {
secondaryTypes.push($(this).text());
});
if(secondaryTypes.length === 0){
getSingleCard(undefined,primaryType, false, dataArray,1);
}
const paths = [];
//Find Ajax URLs for sub categories
for (let j = 0; j < secondaryTypes.length; j++) {
for (const i in dataArray) {
if ((JSON.parse(dataArray[i])).primarycategory === primaryType && (JSON.parse(dataArray[i])).secondarycategory === secondaryTypes[j]) {
paths.push(`${(JSON.parse(dataArray[i])).path}.html`);
}
}
}
if(pathValue===0){
//Reset content area
$('.text.aig-claims-content').html('');
//Create a div to store HTML content
const cards = document.createElement('div');
for (const k in paths) {
if (paths[k]) {
$.ajax({
url: paths[k],
type: 'GET',
dataType: 'html'
}).done(function(data) {
cards.innerHTML += `${sanitizeText(data)}
`;
$(cards).appendTo('.text.aig-claims-content');
});
}
}
}
if(pathValue===1){
//Adding the paths to enterPaths array
for(let s=0;s.cmp-container >.aem-Grid >.hidden input[name="claim-placeholder-text"]');
if(whyhid.length){
let whyaigph = whyhid.attr('value');
setTimeout(function() {
$('.why-aig-container').find('.options.custom-select ul.select-picker li div.filterList input.filterText').attr('placeholder',whyaigph);
},1000);
}
},500);
/* function to why aig placeholder ends*/
/*
Copyright 2016 Adobe
Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
AIG.
Copyright © American International Group,Inc. All rights reserved.
emailto:contact AT dmp-support@aig.com
License as published by the AIG;
2 Peach Tree Hill Rd, Livingston, NJ 07039.
*/
$(document).ready(function () {
/* Create mobile sticky secondary navigation starts*/
if ($('.sticky_navigation ').length > 0) {
if ($('.hamburg').length) {
$(mobilStickySecNav).insertAfter('.hamburg');
} else {
$(mobilStickySecNav).insertAfter('.header-bar');
}
}
});
if ($('.side_nav').length) {
$(mobileModal).insertAfter('.header-bar');
const $baseEdit = $('.side_nav .cmp-navigation__item--level-1.cmp-navigation__item--active').length
? $('.side_nav .cmp-navigation__item--level-1.cmp-navigation__item--active > a').text()
: $('.side_nav .cmp-navigation__item--level-0 > a').text();
if ($('#edit-base').length) {
$('#edit-base').html($baseEdit);
}
const mobilelinks = '' + $('.side_nav nav').html() + ' ';
$('.model-body').append(mobilelinks);
if (window.matchMedia('(min-width:768px)').matches) {
$('.side_nav .cmp-navigation__item--level-1').each(function () {
//we have to go through the lists with children using JS,there is no css selector to do it.
const a = $(this).children().length;
if (a > 1) {
$(this).children('a').append('chevron_right ');
}
});
} else {
$('.mobilemodal .modal-dialog .cmp-navigation__item--level-1').each(
function () {
$(this).children('.custom-icons').remove();
}
);
}
}
/* Custom Carousel - START */
$(function() {
// To target element
const $sliderElement = $('.aig-carousel-v2 > .cmp-container > .aem-Grid');
// Lopp running if the page have multiple carousel section
$sliderElement.each(function(){
const $this = $(this);
const totalItems = $this.find('.teaser').length;
//To wrap addtional markup for carousel
$this.wrapInner('');
// To add Prev & Next button
$this.find('.carousel-container').append(' ');
// To add Inidicators
$this.find('.carousel-container').append('');
// To Initiate carousel
createCarousel($this, totalItems);
});
});
// Define Carousel
function createCarousel($target, totalItems){
const $carouselNext = $target.find('.carousel-arrow-next');
const $carouselPrev = $target.find('.carousel-arrow-prev');
let itemsPerSlide = carouselBreakpoint();
let itemCount = itemsPerSlide;
let slideItemWidth = (100 / itemsPerSlide).toFixed(2);
$target.find('.carousel-list').width((slideItemWidth * totalItems).toFixed(2)+'%');
let noOfSlides = slideCalculator(totalItems,itemsPerSlide);
//for each slide, create slide indicator
$target.each(function(){
for (let i = 1; i<=noOfSlides; i++) {
if(totalItems>itemsPerSlide){
$(this).find('.carousel-slides').append(' ');
}
};
});
$target.find('li[class*="carousel-slide"]:first-child').addClass('active'); //first slide active by default
// Slide Indicator - click event
const slide = $target.find('li[class*="carousel-slide"]');
slide.click(function(){
itemCount = slideIndicator($(this), $target, itemsPerSlide, $carouselPrev, $carouselNext, slideItemWidth, noOfSlides, totalItems);
});
// Next button - click event
$carouselNext.click(function(e){
itemCount = nextArrow(totalItems,itemCount,itemsPerSlide,$target,slideItemWidth,$carouselPrev,$carouselNext);
updateActiveSlide($(e.currentTarget).closest('.carousel-container').find('.carousel-slides li'),Math.ceil(itemCount/itemsPerSlide));
});
// Previous button - click event
$carouselPrev.click(function(e){
itemCount = prevArrow(itemCount,itemsPerSlide,$target,slideItemWidth,$carouselPrev,$carouselNext);
updateActiveSlide($(e.currentTarget).closest('.carousel-container').find('.carousel-slides li'),Math.ceil(itemCount/itemsPerSlide));
});
// show/hide Prev-Next button based on the no.of cards
function buttonConfig(){
if(totalItems <= itemsPerSlide){
$carouselNext.hide(); $carouselPrev.hide();
}else{
$carouselNext.show(); $carouselPrev.show();
}
}
buttonConfig();
// To Resize carousel
$(window).on('orientationchange resize', function() {
// Reset carousel while resizing devices
itemsPerSlide = carouselBreakpoint();
itemCount = itemsPerSlide;
slideItemWidth = (100 / itemsPerSlide).toFixed(2);
// Reset Carousel Container
$target.find('.carousel-list').width((slideItemWidth * totalItems).toFixed(2)+'%');
$target.find('.carousel-list').css('margin-left','0%');
// Reset Prev/next Buttons
$carouselNext.removeClass('cl-disabled');
$carouselPrev.addClass('cl-disabled');
// show/hide Prev-Next button based on the no.of cards while resizing
buttonConfig();
$target.find('.carousel-slides li').remove();
noOfSlides = slideCalculator(totalItems,itemsPerSlide);
$target.each(function() {
for (let i = 1; i<=noOfSlides; i++) {
if(totalItems>itemsPerSlide) {
$(this).find('.carousel-slides').append(' ');
}
};
});
const slide = $target.find('li[class*="carousel-slide"]');
slide.click(function(){
itemCount = slideIndicator($(this), $target, itemsPerSlide, $carouselPrev, $carouselNext, slideItemWidth, noOfSlides, totalItems);
});
let currIndicator = $target.find('.carousel-slides li').attr('data-slide-to');
updateActiveSlide($target.find('.carousel-slides li'),currIndicator);
});
}
//Define carousel Breakpoint
function carouselBreakpoint(){
let itemsPerSlide;
const deviceWidth = $(window).width();
if(deviceWidth < 768){
itemsPerSlide = 1;
}else if(deviceWidth < 1025){
itemsPerSlide = 3;
}else if(deviceWidth < 1201){
itemsPerSlide = 3;
}else{
itemsPerSlide = 3;
}
//slideCalculator(totalItems,itemsPerSlide);
return itemsPerSlide;
}
function slideCalculator(totalItems,itemsPerSlide){
//let slidesPerCarousel;
let totalSlides = Math.ceil(totalItems/itemsPerSlide);
return totalSlides;
}
//function on Carousel Next Arrow
function nextArrow(totalItems,itemCount,itemsPerSlide, $target, slideItemWidth, $carouselPrev, $carouselNext){
if(totalItems > itemCount){
const nextSlide = totalItems - itemCount;
if(nextSlide >= itemsPerSlide){
$target.find('.carousel-list').css('margin-left','-'+(itemCount * slideItemWidth)+'%');
itemCount += itemsPerSlide;
$carouselPrev.removeClass('cl-disabled');
if(totalItems === itemCount){ $carouselNext.addClass('cl-disabled'); }
}else{
$target.find('.carousel-list').css('margin-left','-'+((totalItems - itemsPerSlide) * slideItemWidth)+'%');
itemCount += nextSlide;
$carouselNext.addClass('cl-disabled');
$carouselPrev.removeClass('cl-disabled');
}
}
return itemCount;
}
//function on carousel Previous Arrow
function prevArrow(itemCount,itemsPerSlide, $target, slideItemWidth, $carouselPrev, $carouselNext){
if(itemCount > itemsPerSlide){
const prevSlide = itemCount - itemsPerSlide;
if(prevSlide >= itemsPerSlide){
$target.find('.carousel-list').css('margin-left','-'+((prevSlide-itemsPerSlide) * slideItemWidth)+'%');
itemCount -= itemsPerSlide;
$carouselNext.removeClass('cl-disabled');
if(itemsPerSlide === itemCount){ $carouselPrev.addClass('cl-disabled'); }
}else{
$target.find('.carousel-list').css('margin-left','0%');
itemCount = itemsPerSlide;
$carouselNext.removeClass('cl-disabled');
$carouselPrev.addClass('cl-disabled');
}
}
return itemCount;
}
//function on carousel dot indicators
function slideIndicator($this, $target, itemsPerSlide, $carouselPrev, $carouselNext, slideItemWidth, noOfSlides, totalItems){
$this.siblings().removeClass('active');
$this.addClass('active');
const slideActive = $this.attr('data-slide-to');
const itemsHidden = (slideActive * itemsPerSlide) - itemsPerSlide;
const itemDiff1 = (noOfSlides*itemsPerSlide)-totalItems;
const itemDiff2 = totalItems - itemsHidden;
//if there are less item in a slide
if((itemDiff1 + itemDiff2) === itemsPerSlide){
$target.find('.carousel-list').css('margin-left','-'+((itemsHidden-itemDiff1) * slideItemWidth)+'%');
}
else{
$target.find('.carousel-list').css('margin-left','-'+(itemsHidden * slideItemWidth)+'%');
}
/* enable,disable next/previous arrow based on indicator clicked*/
if(slideActive==1){
$carouselPrev.addClass('cl-disabled');
$carouselNext.removeClass('cl-disabled');
}
else if(slideActive==noOfSlides){
$carouselPrev.removeClass('cl-disabled');
$carouselNext.addClass('cl-disabled');
}
else{
$carouselNext.removeClass('cl-disabled');
$carouselPrev.removeClass('cl-disabled');
}
return slideActive*itemsPerSlide;
}
//Function to update active slide indication
function updateActiveSlide($this, nextActive){
// To update all the slide
$this.each(function(){
if($(this).attr('data-slide-to')==nextActive){
// Update class as acitve or not
$(this).siblings().removeClass('active');
$(this).addClass('active');
}
});
}
/* Custom Carousel - END */
/* AIG Caraousel Method - START */
function aigCarouselDialog(clicked){
//if pop-up is cloosed, unslick the carousel
if(clicked===-1){
$('.timeline-dialog-carousel').each(function(){
$('> .cmp-container > div', $(this)).slick('unslick');
});
}
//if pop-up is opened, show respective slide
else{
$('.timeline-dialog-carousel').each(function(){
const $this = $(this);
const noOfItem = 1;
const noOfItemTablet = 1;
const noOfItemMobile = 1;
const noOfItemMobilesmall = 1;
const arrows = true;
const dots = true;
// To find Timeline-media card
// To hide thumbnails when button is present
if($this.parent().find('.aig-carousel + .button.aig_button').length) {
$this.addClass('hide-thumbnails');
}
// To add slick method
$('> .cmp-container > div', $this).slick({
//setting accessibility to true for ADA compliance
accessibility: true,
//setting to show prev/next buttons
arrows: arrows,
// setting thumbnail visibility to true
dots: dots,
//setting looping to infinite looping
infinite: false,
//setting transition speed for carousel
speed: 300,
//setting fade on carousel slide change
fade: true,
//setting then number of slides to be displayed
slidesToShow: noOfItem,
//setting then number of slides to be scrolled at a time
slidesToScroll: noOfItem,
responsive: [{
//1st breakpoint at 1024px
breakpoint: 1024,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: noOfItemTablet, slidesToScroll: noOfItemTablet, dots: dots
}
}, {
//3rd breakpoint at 768px
breakpoint: 768,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: noOfItemMobile, slidesToScroll: noOfItemMobile
}
}, {
//4th breakpoint at 480px
breakpoint: 480,
//breakpoint settings such as slides to show, slides to scroll etc
settings: {
slidesToShow: noOfItemMobilesmall, slidesToScroll: noOfItemMobilesmall
}
}]
//slickGoTo: clicked-1
});
//goto related slide
$('> .cmp-container > div', $this).slick( 'slickGoTo', clicked-1 , true );
});
}
}
//function to calculate dot indicators top offser
function indicatorOffset(){
$('.teaserflex.aig-timeline-carousel .cmp-teaser').each(function () {
const h = $(this).find('.cmp-teaser__image .cmp-image__image').height();
$(this).find('.cmp-teaser__action-container').css('top', h-55 );
});
}
/* AIG Caraousel Method - END */
$(function () {
const dialogLink = 'a[href^="#timeline-dialog"]';
$(dialogLink).each(function () {
const gethref = $(this).attr('href');
const splithref = gethref.split('#');
$(this).attr({'aria-haspopup': 'true', 'aria-expanded': 'false', 'aria-controls': splithref[1]});
});
//make first image active on load
$(window).on('load',function() {
//make first dot highlighted
$('.teaserflex.aig-timeline-carousel').each(function () {
$(this).find('a[href^="#timeline-dialog"]').first().attr('aria-expanded','true');
});
$('a[href^="#timeline-dialog"]').parent().css({
'position': 'absolute',
'text-align': 'center',
'margin': '0 auto',
'left': '0',
'right': '0'
});
indicatorOffset();
});
$(window).on('resize', function() {
setTimeout(function() {
indicatorOffset();
}, 300);
});
//function to close dialog on cliking cross icon
$(document).on('click', '[id^="timeline-dialog"] .cmp-button__icon--clear', function (e) {
e.preventDefault();
$(this).parents().find('dialog').removeClass('show').addClass('hide');
$(this).parents().find('[id^="timeline-dialog"]').removeClass('dialog-open');
$('html').css('overflow', 'auto');
aigCarouselDialog(-1);
});
//function to show dialog on cliking link
$(document).on('click', dialogLink, function (e) {
e.preventDefault();
$(this).attr('aria-expanded', 'true');
//close other dialogs
$(this).parent().find('a[href^="#timeline-dialog"]').not($(this)).attr('aria-expanded','false');
//get the dot clicked
const slideClicked = $(this).text();
const linkStr = $(this).attr('href').split('#')[1];
$('[id^="timeline-dialog"]').each(function () {
//show only the dialog with matching ID.
if($('.video-player-close').length) {
$('.video-player-close').remove();
}
if($(this).attr('id') === linkStr){
const CURR = $($(this).parent()[0]);
//To Add container class
$(CURR).addClass('aig-timeline-mediacard-container');
if (CURR.hasClass('show')) {
//hide dialog
CURR.removeClass('show').addClass('hide');
$(this).removeClass('dialog-open');
$('html').css('overflow', 'auto');
} else {
//show dialog
CURR.removeClass('hide').addClass('show');
$(this).addClass('dialog-open');
$('html').css('overflow', 'hidden');
//when dialog is opened, call carousel function
aigCarouselDialog(slideClicked);
}
}
});
$('.dialog-open .cmp-button__icon--clear').focus();
return false;
});
});
//on keyboard control
$(document).on('keydown', function (e) {
//if timeline dialog pop-up is visible
if ($('[id^=timeline-dialog]').is(':visible')) {
const $currDialog = $('.dialog-open');
const $focusable = $('.dialog-open [href], .dialog-open button, .dialog-open .slick-current .video_thumbnail:visible');
for (let i = 0; i < $focusable.length; i++) {
//On tab key
if (e.key === 'Tab' || e.keyCode === 9) {
e.preventDefault();
$focusable[i].focus();
}
//Escape to close the dialog
else if (e.which === 27) {
$currDialog.closest('dialog').removeClass('show').addClass('hide');
$currDialog.removeClass('dialog-open');
$('html').css('overflow', 'auto');
const $targetLink = $('[href="#'+ $currDialog.attr('id') +'"][aria-expanded^="true"]');
$targetLink.focus();
$('.timeline-dialog-carousel').each(function () {
$('> .cmp-container > div', $(this)).slick('unslick');
});
}
}
}
});
/*Function to play video on clicking thumbnail image*/
$(document).on('click touchstart', "[id^='timeline-dialog'] .content__img-link", function () {
/*hide clicked thumbnail image*/
$(this).hide();
const currentVideoCmp = $(this).closest('.videocomponent');
currentVideoCmp.find('.video-popup').hide();
const videoUrl = $(this).attr('data-src');
const videoSource = $(' ').attr({src: $(this).data('src'),type: 'video/mp4'});
const videoTrack = $(' ', {kind: 'subtitles', label: $(this).data('caption-lang-label'), src: $(this).data('caption-src'), srclang: $(this).data('caption-lang')});
/*if the video is not youtube*/
if (videoUrl.indexOf('youtube') === -1) {
const videoComponent = $(' ', { id: 'video-player', autoplay: true, controls: true, controlsList: 'nodownload', crossorigin: 'anonymous'}).append(videoSource).append(videoTrack).insertAfter(currentVideoCmp.find('.content__img-link'));
/*hide thumbnail image for current video*/
currentVideoCmp.find('.content__img-link').hide();
/*stop video after video duration ends*/
videoComponent.on('ended', function () {
stopVideo(videoComponent);
});
} else {
$('').insertBefore(currentVideoCmp.find('.player--close'));
let iframeSrc = $(this).data('src');
if (iframeSrc.indexOf('?') !== -1 && iframeSrc.indexOf('autoplay') === -1) {
iframeSrc = iframeSrc + '&autoplay=1';
}
if (iframeSrc.indexOf('?') === -1) {
iframeSrc = iframeSrc + '?autoplay=1';
}
$('', {src: iframeSrc, id: 'iframe-player', frameborder: 0, allow: 'autoplay; encrypted-media', allowfullscreen: true}).appendTo('.iframe-video');
}
});
/*stop video on click of carousel arrows/dialog close/carousel dots*/
$(document).on('click','.slick-arrow , [id^="timeline-dialog"] .cmp-button__icon--clear , .slick-dots li', function () {
$('#video-player, .video-popup .iframe-container').remove();
$('.video_thumbnail').show();
}
);
/*function to stop video*/
function stopVideo(e) {
e.find('#video-player, .video-popup .iframe-container').remove();
/*show thumbnail image*/
e.find('.video_thumbnail').show();
}
/*Copyright 2016 Adobe
Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to
in writing, software distributed under the License is
distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
AIG.
Copyright © American International Group,Inc. All rights reserved.
emailto:contact AT dmp-support@aig.com
This HTML file supports the
AEM touch UI dialog
License as published by the AIG; either
2 Peach Tree Hill Rd, Livingston, NJ 07039.*/
/*
*
* This is js file is used to
* add the generic javascripts for the components
* hero banner
* blade image moble view.
* Also js to make teaser component clickable.
* The code is specific to design2020 code base.
*
*/
/* Code to open content popup --START */
$(document).ready(function() {
//function to open dialog on cliking cross icon
// adding role to to popup links
$('a[href^="#page-dialog-footerlink"]').attr('role','button');
$('dialog.container .cmp-container[id^="page-dialog-footerlink"]').each(function () {
const title = $(this).closest('dialog').attr('aria-labelledby');
const desc = $(this).closest('dialog').attr('aria-describedby');
$(this).find('.cmp-teaser__title').attr('id', title);
$(this).find('.cmp-teaser__description').attr('id', desc);
const a = $(this).find('.cmp-teaser__title-link').text();
$(this).find('.cmp-teaser__title').text(a);
});
// Adding button role to close icon
$('.container [id^=page-dialog-footerlink] .teaserflex .cmp-teaser__action-link').attr('role','button');
$('[id^=page-dialog-footerlink]').attr('role','document');
//Accessibilty changes to dialog tag
// attributes which contain dash(-) should be covered in quotes.
//on click of pop-up link
$('a[href^="#page-dialog-footerlink"]').on('click', function() {
const targetRef = $(this).attr('href');
$(targetRef).parent().addClass('popup-dialog');
//close all dialogs except the targeted one
closeDialog($('[id^=page-dialog-footerlink]').not(targetRef));
$(this).addClass('open-popup');
//focus on the dialog once opened focus on close icon
setTimeout(function () {
$(targetRef).attr('tabindex', 0);
$(targetRef).find('.teaserflex .cmp-teaser__action-link').filter(function() {
return $(this).text() === 'close';
}).focus();
}, 500);
//code to trap focus while the dialog is opoen
if($('.open-popup').length){
const focusableEls = $('.popup-dialog').find('a[href], button');
const firstFocusableEl = focusableEls[0];
const lastFocusableEl = focusableEls[focusableEls.length - 1];
const KEYCODE_TAB = 9;
$('[id^=page-dialog-footerlink]').on('keydown', function(e) {
const isTabPressed = (e.key === 'Tab' || e.keyCode === KEYCODE_TAB);
if (!isTabPressed) {
return;
}
if ( e.shiftKey ) /* shift + tab */ {
if (document.activeElement === firstFocusableEl) {
lastFocusableEl.focus();
e.preventDefault();
}
} else /* tab */ {
if (document.activeElement === lastFocusableEl) {
firstFocusableEl.focus();
e.preventDefault();
}
}
});
}
});
// Close dialog on clicking x icon
$('.container [id^=page-dialog-footerlink] .teaserflex .cmp-teaser__action-link[href^="#"]').click(
function (event) {
//to prevent the page scroll to top on close of dialog
event.preventDefault();
//closing the dialog
closeDialog($(this));
}
);
});
//function to close dialog
function closeDialog(curr) {
curr.parents('dialog.container').removeClass('popup-dialog');
if($('.open-popup').length){
$('.open-popup').focus().attr({ tabindex: '0' }).removeClass('open-popup');
} else {
$('[href^="#page-dialog-footerlink-1"]').focus().attr({ tabindex: '0' });
}
}
/* Code to open content popup --ENDS */